Link to home
Start Free TrialLog in
Avatar of srikanthradix
srikanthradixFlag for United States of America

asked on

Spool Query in Oracle

How to spool the output of an sql query into a CSV file?

select * from table1 group by column1;

And the select statement should not print anything to the System Out. How to do that?
Avatar of yuching
yuching

Perhaps can try this in sqlplus

Set define Off;
Set feedback Off;
Set serveroutput On;
SET PAGESIZE 0
SET LINESIZE 1000
Spool results.log

select * from table1 group by column1;

Spool Off;
Set define On;
Set feedback On;
Avatar of Naveen Kumar
if you have toad, you can execute the query and give mouse click and save as "you can find one of  the option for saving it as csv file".

if you want to do it in sql*plus, then save the below in a testing.sql file and run it from sqlplus prompt

set echo off   -- this is to ensure that sql statement is not printed in the spool file
set feedback off
spool output.csv  -- to create a file named output.csv

select * from table1 group by column1;

spool off
set echo on
set feedback on
Avatar of srikanthradix

ASKER

Hi everyone,

I am using SQL Plus Worksheet & Oracle SQL Developer, it is spooling to the CSV file & still printing it to the output
The sqlplus "set" options doesnt work from the SQL Developer screen.
You have to use the "sqlplus" tool itself for that.
select * from table1 group by column1;
put this sql statement in a file  for eg: a.sql
Set echo off;
Set define Off;
Set feedback Off;
Set serveroutput On;
SET PAGESIZE 0
SET LINESIZE 1000
Spool results.log

start a.sql;

Spool Off;
Set define On;
Set feedback On;
Set echo off;
Set define Off;
Set feedback Off;
Set serveroutput On;
SET PAGESIZE 0
SET LINESIZE 1000
Spool c:/results.log

start c:/stmt.sql;

Spool Off;
Set define On;
Set feedback On;

It is writing to file. But, Still writing to output screen.
ASKER CERTIFIED SOLUTION
Avatar of Naveen Kumar
Naveen Kumar
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial