"spool off; /" '/' 的意义 post 假脱机
"spool off; /" significance of '/' post spool off
请帮助我解决我面临的以下问题。
我有一些现有的 shell 脚本,它们每天定期 运行 将一些数据假脱机到文本文件中并将其发送到另一个系统。
现在我对那些脚本和假脱机做了一些更改,过去需要 6 个小时,现在需要 8 个多小时。
我看过脚本中的“/”通常执行前面的sql语句。
那么通过下面的代码,sql 查询是否被调用了两次?
我是新手,抱歉,如果我太天真了,任何与此相关的帮助都将不胜感激。
提前致谢。
#!/bin/ksh
ORACLE_HOME=/pprodi1/oracle/9.2.0; export ORACLE_HOME;
Script_Path=<path>
dt=`date '+%y%m%d%H%M'`
find $Script_Path/testing_spool* -mtime +3 | xargs rm -f { }
cd $Script_Path
sqlplus -s uname/pwd@db_name<<EOF1>/dev/null
set echo off
set head off
set pages 0
set feedback off
set pause off
set colsep " "
set verify off
set termout off
set linesize 3000
set trimspool on
spool $Script_Path/testing_spool.dat
SELECT column_name
FROM table_name
WHERE created_date > SYSDATE - 1
AND col1 = '126'
AND col2 = 'N'
AND col3 = 6;
spool off;
/
EOF1
cat testing_spool.dat > testing_spool_$dt.txt
是的,您的查询将执行两次,一次是在假脱机处于活动状态时,另一次是在假脱机关闭后再次执行。
如您所述,/
executes whatever is currently in the SQL buffer 仍将包含您的查询。 spool off
是客户端命令,不会影响 SQL 缓冲区。
如果您 运行 您的脚本在第 10 行没有输出重定向 >/dev/null
,或者如果您期望大量输出则重定向到一个文件,那么您将看到重复的查询结果。
顺便说一下,set termout off
没有在您的脚本中执行任何操作,因为您 运行 将其作为 heredoc。如果您在脚本文件中有语句并且 运行 使用 start
或 @
那么它会抑制输出,但是 as the documentation says:
ECHO does not affect the display of commands you enter interactively or redirect to SQL*Plus from the operating system.
您可能会创建一个 .sql 文件,运行 那个文件,然后删除它 - 所有这些都在您的 shell 脚本中。您可能看不到太多好处,但这意味着您不需要使用该重定向隐藏所有输出,这将使诊断故障变得更加困难。
请帮助我解决我面临的以下问题。
我有一些现有的 shell 脚本,它们每天定期 运行 将一些数据假脱机到文本文件中并将其发送到另一个系统。
现在我对那些脚本和假脱机做了一些更改,过去需要 6 个小时,现在需要 8 个多小时。
我看过脚本中的“/”通常执行前面的sql语句。 那么通过下面的代码,sql 查询是否被调用了两次?
我是新手,抱歉,如果我太天真了,任何与此相关的帮助都将不胜感激。
提前致谢。
#!/bin/ksh
ORACLE_HOME=/pprodi1/oracle/9.2.0; export ORACLE_HOME;
Script_Path=<path>
dt=`date '+%y%m%d%H%M'`
find $Script_Path/testing_spool* -mtime +3 | xargs rm -f { }
cd $Script_Path
sqlplus -s uname/pwd@db_name<<EOF1>/dev/null
set echo off
set head off
set pages 0
set feedback off
set pause off
set colsep " "
set verify off
set termout off
set linesize 3000
set trimspool on
spool $Script_Path/testing_spool.dat
SELECT column_name
FROM table_name
WHERE created_date > SYSDATE - 1
AND col1 = '126'
AND col2 = 'N'
AND col3 = 6;
spool off;
/
EOF1
cat testing_spool.dat > testing_spool_$dt.txt
是的,您的查询将执行两次,一次是在假脱机处于活动状态时,另一次是在假脱机关闭后再次执行。
如您所述,/
executes whatever is currently in the SQL buffer 仍将包含您的查询。 spool off
是客户端命令,不会影响 SQL 缓冲区。
如果您 运行 您的脚本在第 10 行没有输出重定向 >/dev/null
,或者如果您期望大量输出则重定向到一个文件,那么您将看到重复的查询结果。
顺便说一下,set termout off
没有在您的脚本中执行任何操作,因为您 运行 将其作为 heredoc。如果您在脚本文件中有语句并且 运行 使用 start
或 @
那么它会抑制输出,但是 as the documentation says:
ECHO does not affect the display of commands you enter interactively or redirect to SQL*Plus from the operating system.
您可能会创建一个 .sql 文件,运行 那个文件,然后删除它 - 所有这些都在您的 shell 脚本中。您可能看不到太多好处,但这意味着您不需要使用该重定向隐藏所有输出,这将使诊断故障变得更加困难。