Call now: 919-335-6342  
Oracle Training Oracle Support Development Oracle Apps

 E-mail Us
 Oracle Articles
New Oracle Articles

 Oracle Training
 Oracle Tips

 Oracle Forum
 Class Catalog

 Remote DBA
 Oracle Tuning
 Emergency 911
 RAC Support
 Apps Support
 Oracle Support

 SQL Tuning

 Oracle UNIX
 Oracle Linux
 Remote s
 Remote plans
 Application Server

 Oracle Forms
 Oracle Portal
 App Upgrades
 SQL Server
 Oracle Concepts
 Software Support

 Remote S


 Consulting Staff
 Consulting Prices
 Help Wanted!


 Oracle Posters
 Oracle Books

 Oracle Scripts

Don Burleson Blog 







Oracle spool tips

Oracle Database Tips by Donald Burleson

January 2023

Question:  I want to see an example of the SQL*Plus spool command.  What is the purpose of spooling output in SQL*Plus?

Answer:  The SPOOL command causes SQL*Plus to write the results to a file on the operating system.

SQL> spool /tmp/myfile.lst

Once spool is set, SQL*Plus will continue to spool the output until the command SPOOL OFF. Note that the file cannot be seen or used until the SPOOL OFF command.

The spool command is very useful when you want to generate SQL from the data dictionary.  Here is an example of a SQL*Plus spool command:

spool runme.sql

select 'select * from dba_tables' where table_name like 'FRED%';

spool off;


Using the Oracle spool command

The "spool" command is used within SQL*Plus to direct the output of any query to a server-side flat file.

SQL> spool /tmp/myfile.lst

Becuse the spool command interfaces with the OS layer, the spool command is commonly used within Oracle shell scripts. 

You have several options for writing conditional messages to a SQL*Plus spool file.  I would just check the spool file size after you execute it:

$ORACLE_HOME/bin/sqlplus system/manager<<!
spool myfile.txt
select owner,object_type,object_name
from dba_objects
where status='INVALID';
spool off

if [ `cat myfile.txt|wc -l` -lt 1 ]
then echo Check Status OK > myfile.txt


Writing dates into spool comands

For example, say that you want to run a SQL*Plus script where it spools to a file name that contains SYSDATE.  How do you add SYSDATE to a spool file name?

name.   You can select SYSDATE into a variable name using the DUAL pseudo-table, and execute the name as part of the spool command:

sqlplus . . .
select 'invoice_'||to_char(sysdate, 'yymmdd') spoolname from dual
spool '&spoolname'
select stuff . . . .
spool off

Using the Oracle spool append command

if you spool out a file that does not exist, SQL*Plus creates a new file.  SQL*Plus replaces the existing file if the file name already exists.  In Oracle 10g, the SPOOL command has a new APPEND option.  Now, you can append new SQL*Plus output in an existing file. 

Get the Complete
Oracle SQL Tuning Information 

The landmark book "Advanced Oracle SQL Tuning  The Definitive Reference"  is filled with valuable information on Oracle SQL Tuning. This book includes scripts and tools to hypercharge Oracle 11g performance and you can buy it for 30% off directly from the publisher.

This is the BC Oracle DBA Scripts collection with Oracle DBA Scripts for tuning, monitoring, a professional download of over 600 Oracle DBA Scripts.



Burleson is the American Team

Note: This Oracle documentation was created as a support and Oracle training reference for use by our DBA performance tuning consulting professionals. 

Verify experience! Anyone considering using the services of an Oracle support expert should independently investigate their credentials and experience, and not rely on advertisements and self-proclaimed expertise.

Errata?  Oracle technology is changing and we strive to update our BC Oracle support information.  If you find an error or have a suggestion for improving our content, we would appreciate your feedback.  Please  e-mail:  

and include the URL for the page.



Burleson Consulting

The Oracle of Database Support

Oracle Performance Tuning

Remote DBA Services


Copyright © 1996 -  2023

All rights reserved by Burleson

Oracle ® is the registered trademark of Oracle Corporation.



Oracle Training at Sea
oracle dba poster

Follow us on Twitter 
Oracle performance tuning software 
Oracle Linux poster