Oracle SQLPlus Query Output to a File

| Posted by watashii | Filed under Database, Programming, Unix

Here 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

Share:

  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Print
  • email

Related Posts:

  1. Starting / Shutdown Oracle Database in Unix
  2. Oracle SQL Loader – Importing CSV files to a table
  3. UNIX file size listing – du command
  4. Unix – Creating Cron Jobs with Crontab
  5. Unix Split, Join & Validate Files

Tags: , , , ,

Leave a Reply