Home > Oracle DBA > Export from Oracle table to CSV file

Export from Oracle table to CSV file

June 10, 2013

Sometimes you need to export result of the query to CSV file. Here is a nice example of how to do this kind of operations.

SQL> set colsep ,

SQL> SET LINESIZE 5000 FEEDBACK OFF TRIMSPOOL ON TERMOUT OFF HEAD OFF PAGESIZE 0 TERM OFF

SQL> spool outfile.csv

SQL> select * from mytable where [your where statement]

SQL> spool off

SQL> exit

Update: SET LINESIZE determines a maximum number of characters in the line. So if you expect output bigger than 5000 lines you must set this to a bigger value.

Categories: Oracle DBA