Work With Results Through Technology to Grow Your Business Contact Us Today

Hide
Show
Categories: Technical Tips

The SQL*Plus COLUMN command allows you to have SELECT statement results stored into a SQL*Plus variable. You can then use that variable later in your SQL*Plus script. The two scripts below are simple examples of this capability.

rem 
rem Get the database name and use it in the spool command to spool to a file that 
rem is named according to the database name.
rem
column db_name noprint new_value db_name
select name db_name from v$database;
spool &db_name..rpt

rem
rem Set the output linesize to the maximum length of any data in the column that you are
rem selecting.
rem
set pagesize 0
set feedback off
column line_size noprint new_value line_size
select max(length(mydata)) line_size from mytable;
set linesize &line_size
spool mytable.rpt
select mydata from mytable;
spool off

 

Spread the Word, like or share this page, your friends will also love it and thanks for it.

About the Author

Scott Nelson is an entrepreneur, Oracle wizard, consultant, businessman, filmmaker, inventor, tinkerer. He’s always been willing to approach the unapproachable, attempt the impossible, reach for the brass ring in a wild dive into the darkness of the unknown because his motto is “All you have to do is do it” Currently living the good life in southern Indiana amongst the hills and pleasant valleys of Brown County.

Top