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

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

Expert Comment

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

Author Comment

ID: 35037073
thankyou, I'll try these two and get back
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.


Author Comment

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?
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
LVL 14

Accepted Solution

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


LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 35095228

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


Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Suggested Solutions

Title # Comments Views Activity
PL/SQL Display based on value 4 39
SQL2016 to ORACLE11G linked-server 6 29
Using SQL*PLUS issue with where statement with trunc function 3 29
Error in creating a view. 8 23
Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
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 shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

820 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