Call now: 252-767-6166  
Oracle Training Oracle Support Development Oracle Apps

 
 Home
 E-mail Us
 Oracle Articles


 Oracle Training
 Oracle Tips

 Oracle Forum
 Class Catalog


 Remote DBA
 Oracle Tuning
 Emergency 911
 RAC Support
 Apps Support
 Analysis
 Design
 Implementation
 Oracle Support


 SQL Tuning
 Security

 Oracle UNIX
 Oracle Linux
 Monitoring
 Remote s
upport
 Remote plans
 Remote
services
 Application Server

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

 Remote S
upport  
 Development  

 Implementation


 Consulting Staff
 Consulting Prices
 Help Wanted!

 


 Oracle Posters
 Oracle Books

 Oracle Scripts
 Ion
 Excel-DB  

Don Burleson Blog 


 

 

 


 

 

 
 

Oracle spool tips

Oracle Tips by Burleson Consulting

March 27, 2012

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;

@runme

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
exit
!

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

 

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.

 

 

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.  Feel free to ask questions on our Oracle forum.

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. All legitimate Oracle experts publish their Oracle qualifications.

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.  Just  e-mail:  and include the URL for the page.


                    









Burleson Consulting

The Oracle of Database Support

Oracle Performance Tuning

Remote DBA Services


 

Copyright ? 1996 -  2014

All rights reserved by Burleson

Oracle ? is the registered trademark of Oracle Corporation.


 

  
 

 
 
 
 
 

 
 
 
 
 
 
Oracle training Excel
 
Oracle performance tuning software