Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Spool Query in Oracle

Posted on 2008-10-02
7
Medium Priority
?
4,707 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
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
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 2000 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

TCP/IP Network Protocol Cheat Sheet

TCP/IP is a set of network protocols which is best known for connecting the machines that make up the Internet. The truth is that TCP/IP is one of the oldest network protocols and its survival is mainly based on its simplicity and universality.

Question has a verified solution.

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

This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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

722 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