MEHMET BALiOGLU

Sql Developer Export to Excel With One Line of Code

Export SQL Query Results to Excel File

Sometimes you may need to get the results of the SQL query to a .csv file or an Excel file. Perhaps you want to open it in Excel and make some alterations or some calculations as Excel still offers more convenience compared to SQL, particularly for relatively smaller datasets, or may be you want to draw some graphs which is as easy as clicking a few buttons in Excel. In this article we show how to perform SQL Developer export to Excel with one line of code.

SQL Developer offers an export facility for exporting data to a number formats, including xslx , csv, txt, json and sql insert. However, I find them a little inconsistent. You may need to adjust export settings and the result is not always as exactly as you desire. This was so to my experience, at least.

Exporting query results to Excel in Oracle SQL Developer is so easy. Just add a spool command to the head of your code and add a /*.csv*/ hint to the select command.

spool "/Users/mehmet/Documents/python_binance/after_squeeze_10days.csv"

select /*csv*/ t.* from squeeze_on t

The above code will export the query results to the after_squeeze_10days.csv file.

That’s it. Now you can easily perform “SQL Developer export to Excel” with one line of code to a csv file. This method is easier than its alternatives. You can export SQL Developer query results not only to .csv format, but other formats as well. Don’t forget to run your code as script.