Friday, June 29, 2012

Query Results as CSV in Oracle SQL Developer

I have been using Oracle SQL Developer a lot this week, and have been exporting query data as CSV a lot too: right clicking on the results > selecting Export and going through the dialogs.

Now there is a super cool much easier way. Run your SQL like this:

select /*CSV*/* from MYTABLE;

Then just select all on the results screen and copy/paste the results directly into an Excel spreadsheet! Unfortunately you have to select all twice if you have more than 500 results (you can't override Tools > Preferences > Database > Advanced > SQL Array Fetch Size to be greater than 500).

Thanks to Jeff Smith's blog post: Formatting Query Results to CSV in Oracle SQL Developer. Thanks as well to Ian Carpenter's answer on this StackOverflow question: how to export query result to csv in Oracle SQL Developer?

Actually this isn't working for me in Oracle SQL Developer 3.0.04 - Jeff Smith's solution says you run script (F5) and all I see then is text output of the query i.e. tab delimited, no quotes.. *sigh*