Skip to Main Content
  • Questions
  • Spool to a TXT file but not the LOG file when calling SQLPLUS from Unix Shell Script

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question, Syed W.

Asked: July 20, 2016 - 7:12 pm UTC

Last updated: July 21, 2016 - 9:54 am UTC

Version: Oracle 11G

Viewed 10K+ times! This question is

You Asked

Hi Tom,
How do I spool the output of a Query to a TXT file but not the LOG file when calling SQLPLUS from a Unix Shell Script. Below is the actual code:

===========

Shell Script Script_1.sh:

. ./Script_2.sh > Script_1.log

----------


Shell Script Script_2.sh:

sqlplus -s id/passwd@db << EOF
set heading off
set feedback off
set termout off

spool emp.txt

select * from emp;

spool off

EOF

===========


In the above example, I want the output of the "select * from emp" in the file emp.txt but not Script_1.log. Though I have "set termout off", it still spools the output to Script_1.log.


and Chris said...

Set termout off applies when you're calling scripts. So if you want to supress the output, but still have it spool, place your query in a script:

sqlplus -s id/passwd@db << EOF

set heading off
set feedback off
set termout off

spool emp.txt

@emp.sql

spool off

EOF

And the contents of emp.sql is:
select * from emp;


Is this answer out of date? If it is, please let us know via a Comment