Solved

Spool Query in Oracle

Posted on 2008-10-02
7
4,674 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

710 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