开发者

How to export query result to csv in Oracle SQL Developer?

开发者 https://www.devze.com 2023-01-25 01:13 出处:网络
I\'m using Oracle SQL Developer 3.0. Trying to figure out how to export a query result to a text file (preferably CSV). Right clicking on开发者_如何学Go the query results window doesn\'t give me any e

I'm using Oracle SQL Developer 3.0. Trying to figure out how to export a query result to a text file (preferably CSV). Right clicking on开发者_如何学Go the query results window doesn't give me any export options.


Version I am using

How to export query result to csv in Oracle SQL Developer?

Update 5th May 2012

Jeff Smith has blogged showing, what I believe is the superior method to get CSV output from SQL Developer. Jeff's method is shown as Method 1 below:

Method 1

Add the comment /*csv*/ to your SQL query and run the query as a script (using F5 or the 2nd execution button on the worksheet toolbar)

select /*csv*/ *
from emp;

How to export query result to csv in Oracle SQL Developer?

That's it.

You can also use spool to automatically save it as a CSV file:

spool "/path/to/file.csv";
select /*csv*/ *
from emp;
spool off;

Just be sure to "Run as Script" or press F5.

Method 2

Run a query

How to export query result to csv in Oracle SQL Developer?

Right click and select unload.

Update. In Sql Developer Version 3.0.04 unload has been changed to export Thanks to Janis Peisenieks for pointing this out

How to export query result to csv in Oracle SQL Developer?

Revised screen shot for SQL Developer Version 3.0.04

How to export query result to csv in Oracle SQL Developer?

From the format drop down select CSV

How to export query result to csv in Oracle SQL Developer?

And follow the rest of the on screen instructions.


Not exactly "exporting," but you can select the rows (or Ctrl-A to select all of them) in the grid you'd like to export, and then copy with Ctrl-C.

The default is tab-delimited. You can paste that into Excel or some other editor and manipulate the delimiters all you like.

Also, if you use Ctrl-Shift-C instead of Ctrl-C, you'll also copy the column headers.


FYI, you can substitute the /*csv*/ for other formats as well including /*xml*/ and /*html*/. select /*xml*/ * from emp would return an xml document with the query results for example. I came across this article while looking for an easy way to return xml from a query.


FYI to anyone who runs into problems, there is a bug in CSV timestamp export that I just spent a few hours working around. Some fields I needed to export were of type timestamp. It appears the CSV export option even in the current version (3.0.04 as of this posting) fails to put the grouping symbols around timestamps. Very frustrating since spaces in the timestamps broke my import. The best workaround I found was to write my query with a TO_CHAR() on all my timestamps, which yields the correct output, albeit with a little more work. I hope this saves someone some time or gets Oracle on the ball with their next release.


To take an export to your local system from sql developer.

Path : C:\Source_Table_Extract\des_loan_due_dtls_src_boaf.csv

    SPOOL "Path where you want to save the file"
    SELECT /*csv*/ * FROM TABLE_NAME;


CSV Export does not escape your data. Watch out for strings which end in \ because the resulting \" will look like an escaped " and not a \. Then you have the wrong number of " and your entire row is broken.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号