Oracle SQLPlus Query Output to a File
| Posted by watashii | Filed under Database, Programming, UnixHere is a simple way to output SQL query output into a file, via command line based SQLPlus.
Step 1: Nominate the output file location. In this case this is a Unix location.
SQL> spool /tmp/output.txt
Step 2: Perform your SQL query.
SQL> select * from tab;
Step 3: Close the file.
SQL> spool off
Tip: Use set lines statement to adjust output display
The other method is doing this outside of SQLPlus in a single command. Within the Unix shell, you can write your SQL query statements within an input sql file; eg input.sql, and redirect the output to output.txt.
# sqlplus USER/PASS@DBSID < /tmp/input.sql > /tmp/output.txt
Related Posts:
- Starting / Shutdown Oracle Database in Unix
- Oracle SQL Loader – Importing CSV files to a table
- UNIX file size listing – du command
- Unix – Creating Cron Jobs with Crontab
- Unix Split, Join & Validate Files
Tags: log, oracle, sql, sqlplus, unix
