Solved

how to store output of an sql query to a text file in oracle 11g

Posted on 2011-03-04
7
898 Views
Last Modified: 2013-12-19
how to store output of an sql query to a text file in oracle 11g
0
Comment
Question by:pegahelpdesk1
[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
  • 4
  • 2
7 Comments
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 35037038
Copy of what I posted in your other question.  You should not ask the same question in different places.
-------------------------------------------------

In sqlplus use the SPOOL command.  There are a lot of sqlplus options you can set and you can actually create very nice reports.


The basic commands go like:
spool myFile.txt
select ... from table;
spool off

If you want more detailed advice on how to use sqlplus and create a specific format, ask.
0
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 35037046
The alternative is a stored procedure using UTL_FILE.

http://download.oracle.com/docs/cd/E11882_01/appdev.112/e16760/u_file.htm#ARPLS70896
0
 

Author Comment

by:pegahelpdesk1
ID: 35037073
thankyou, I'll try these two and get back
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:pegahelpdesk1
ID: 35037155
I tried the spool option and I am getting the query also in the text file, can I create a text file where only output shows up and the query used for generating the output is not written to file?
0
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 35037208
>> tried the spool option and I am getting the query also in the text file

Are you copying and pasting the code I posted directly into sqlplus?

Don't do that.

Create a script file with those commands in it.  Say, myscript.sql

then execute the script:
sqlplus user/password @myscript.sql
0
 
LVL 14

Accepted Solution

by:
ajexpert earned 500 total points
ID: 35044138
Here are the steps

1.  You should create a script and embed your query in it.  Just like attached file query.sql.
2.  Create script and embed the SET commands, make sure the paths are correct.  See attached file spool_query.txt
3.  navigate to directory where spool_query.txt is stored
4.  Connect to sql plus with user name and password
5.  execute the script with @spool_query.txt and check the spool file for query output

HTH
 spool-query.txt

 query.sql
0
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 35095228
pegahelpdesk1,

Can I ask why you selected the answer you did when it basically repeated everything I had already said?

0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
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.
Suggested Courses

624 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