SQL Plus中的SET TERMOUT
Posted dingdingfish
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SQL Plus中的SET TERMOUT相关的知识,希望对你有一定的参考价值。
起因是我写了一个脚本,需要用spool命令将SQL Monitor的输出存放在文件中,但不想输出到屏幕上。
脚本的结构如下:
set timing on
sql_statement_here
set timing off
spool sqlmonitor.html
SELECT DBMS_SQL_MONITOR.REPORT_SQL_MONITOR(report_level => 'ALL', type => 'ACTIVE') FROM dual;
spool off
由于SQL monitor的输出已经存放到html文件中,我并不需要在屏幕上输出。这是可以用SET TERMOUT命令。
修改后的脚本如下:
set timing on
sql_statement_here
set timing off
set termout off
spool sqlmonitor.html
SELECT DBMS_SQL_MONITOR.REPORT_SQL_MONITOR(report_level => 'ALL', type => 'ACTIVE') FROM dual;
spool off
set termout on
SET TERMOUT的说明见文档:
Controls the display of output generated by commands in a script that is executed with @, @@ or START. OFF suppresses the display so that you can spool output to a file without displaying the output on screen. ON displays the output on screen. TERMOUT OFF does not affect output from commands you enter interactively or redirect to SQL*Plus from the operating system.
注意,此设置仅对以@,@@和START执行的脚本生效。
例如以下的a.sql文件:
set timing on
set termout off
select sysdate from dual;
执行效果如下:
$ sqlplus -S ssb/$SSBPWD@orclpdb1 @a.sql
$ sqlplus -S ssb/$SSBPWD@orclpdb1 <a.sql
SYSDATE
---------
14-OCT-22
Elapsed: 00:00:00.00
当然,交互执行也不受影响:
SQL> set timing on
SQL> set term off
SQL> select sysdate from dual;
SYSDATE
---------
14-OCT-22
Elapsed: 00:00:00.00
以上是关于SQL Plus中的SET TERMOUT的主要内容,如果未能解决你的问题,请参考以下文章