Solved

Spool Query in Oracle

Posted on 2008-10-02
7
4,651 Views
Last Modified: 2013-12-18
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?
0
Comment
Question by:srikanthradix
7 Comments
 
LVL 11

Expert Comment

by:yuching
ID: 22630147
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;
0
 
LVL 28

Expert Comment

by:Naveen Kumar
ID: 22631160
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
0
 

Author Comment

by:srikanthradix
ID: 22631262
Hi everyone,

I am using SQL Plus Worksheet & Oracle SQL Developer, it is spooling to the CSV file & still printing it to the output
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 27

Expert Comment

by:sujith80
ID: 22631496
The sqlplus "set" options doesnt work from the SQL Developer screen.
You have to use the "sqlplus" tool itself for that.
0
 
LVL 15

Expert Comment

by:Shaju Kumbalath
ID: 22631546
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;
0
 

Author Comment

by:srikanthradix
ID: 22764147
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.
0
 
LVL 28

Accepted Solution

by:
Naveen Kumar earned 500 total points
ID: 22764534
Can you try the below :

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

start c:/stmt.sql

Spool Off  
Set define On
Set feedback On
set termout on
set serveroutput on

FYI: --> for sql*plus commands you don't need a ; at the end
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now