Reputation: 554
I need to get the column names in the result set in oracle select query. When i copy the result set in Oracle SQL Developer
to excel only the data gets copied. not column names.
I know i can use dba_tab_columns
to get the column information of a table but i want a way to include it in the row format with the result.
Also i do not want to hard code the column names with a union
query as there are many tables i need to take and lot of columns.
Export option also doesnt work for me as i am connecting to a remote server using Citrix. so it saves to the remote machine path. not the local path
Upvotes: 3
Views: 2709
Reputation: 49062
SQL Developer provides a lot of options. And you might be missing something, else the Export option to save the query result as Excel does the job.
Upvotes: 3
Reputation: 3734
There's an awesomely easy way to achieve what you want. If I got you right, you copy/paste the results to excel, right?
However, if you want to have the full data (including the column names), you just have to execute your query as a script.
There's a button "Execute script" next to the "normal" "play button".
You'll get something like this as the result:
C1 C2 C3 C4 C5
---------------------- ------------------------------ ------------------------- ----- ------
8 SOMETHING 1337 A 1337
You are able to copy this output completely in your clipboard ans paste it in excel.
Upvotes: 1
Reputation: 172408
You can use the UNION trick:
SELECT 'column1',
'column2',
'column3',
1 AS x
FROM yourTable
UNION
SELECT column1,
column2,
column3,
2 AS x
FROM yourTable
ORDER BY x;
If the number of columns is huge then you can use the dba_tab_columns
to get the column names from your table and do the UNION
logic.
Upvotes: 2