Generate a CSV file from Oracle

Create a CSV file using SQL Developer or SQLcl

Posted by Rookpoint on Monday, November 11, 2019

Overview

It is straightforward to generate a CSV (Comma Separated Values) file from an Oracle database using one of the free tools that Oracle provides:

A simple example is shown below. Enter the following text into a SQL Developer Worksheet.

set sqlformat csv
select * from dual;

Execute the statements using the F5 - Run Script command.

NB: Using the Run Statement command will not work.

The CSV file output will appear in the Script Output window.

Output

From the Script Output window, either click the Save icon, or Copy/Paste the lines directly.

Be aware that if you Run the statement more than once, then the Script Output window will not overwrite your output but will append it to the end of the window. Always use the Clear icon before re-running the same Script or executing a different Script in the same Worksheet.

Example

The references made above are shown here.

SQL Developer Example

This example screenshot is from SQL Developer v20.

NB: The current default limit on script output from SQL Developer is set to 5000 rows. If your output exceeds this number of records then you will need to amend the limit value in Tools > Preferences. The setting is under Database / Utilities / Worksheet.