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.
Wednesday, April 23, 2008
SQL> SET LINESIZE 500 FEEDBACK OFF TRIMSPOOL ON TERMOUT OFF HEAD OFF PAGESIZE 0 TERM OFF
SQL> spool outfile.csv
SQL> select '"'|| column_1 || '",' || column_2 || ',' || column_3 from mytable where [your where statement]
SQL> spool off
In this case column_1 data will be surrounded by "" (you may need this if you have , character in field data).
Update: SET LINESIZE determines a maximum number of characters in the line. So if you expect output bigger than 500 lines you must set this to a bigger value.