Thursday, June 18, 2009

Oracle tables to Excel

set echo off pagesize 0 head off feed off veri off
set trimspool on feedback off
spool FILE_NAME.csv
select COL1 || ',' || COL2 || ',' || COL3 || ',' ||........ from TABLE_NAME;
spool off

If table data contain any 'comma' in middle , then follow this below steps: -

set echo off pagesize 0 head off feed off veri off
set trimspool on feedback off
spool FILE_NAME.txt
select COL1 || '~' || COL2 || '~' || COL3 || '~' ||........ from TABLE_NAME;
spool off

open the .txt file in MS-Excel. Selecting the separator option with '~'