Solved

Spool Query in Oracle

Posted on 2008-10-02
7
4,663 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
sql server computed columns 11 31
T-SQL: Do I need CLUSTERED here? 13 42
Query Help - MSSQL - Averages 5 27
Mysql Left Join Case 10 53
Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

770 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