Generate CSV from SQL*Plus

Generate CSV from SQL*Plus

Just a short post. How to quickly output to CSV when using SQL*Plus with Oracle. Save the following to a file export_to_csv.sql:

set linesize 32767;
set heading on;
set headsep ,;
set colsep ,;
set pagesize 50000;
set trimspool on;
set termout off;
set feed off;
set underline off;
set echo off;

spool /path/to/export.csv;
-- your sql here
select * from table_name;
spool off;

Afterwards, log in to SQL*Plus and run using the command:

SQL> @export_to_csv.sql

Leave a Reply

Your email address will not be published.