Subscribe to this feed

Navigation

Recent Posts

Archive

SQL*Plus Spool File

Saturday 24 Mar, 2007 - 12:40pm | 1 comments |

If you want to produce a csv file from a SQL select query in SQL*Plus use the following syntax.

set echo off
set heading off
set feedback off
set pagesize 0
spool c:\filename.csv
select col1||','||col2 from db_table;
spool off

This will produce a csv formatted file. Straight to excel, change csv to xls but bear in mind two potential issues (a) row limit in Excel, and (b) leading zeros in number fields will be lost in excel.

The leading zeros can be resolved if you instead spool the file as a txt as you will be forced to use excels conversion wizard to open the file.

Posted in: Business
Tags: Oracle | SQL | SQL*Plus | csv

Comment
 | Link | back to top | del.icio.us digg it furl reddit

..

Wednesday 29 Sep, 2010 - 15:44pm
You can use: set colsep , instead of concatenating the fields... -- Andres Santana

Posted by: Anonymous


© Eriginal Ltd 2011, all rights reserved