如何检测当前SCAN
状态并在更改后将其恢复?
来自相关剧本的摘录:
SET SCAN OFF
SET ECHO ON
SET SQLBLANKLINES ON
SET SCAN ON
UPDATE TABLE_NAME SET CREATED_BY = &&created_by;
SET SCAN OFF
问题是如果脚本没有第一行(SET SCAN OFF
),那么提示用户的代码不应该在之后关闭SCAN
状态。伪代码解决方案:
-- The next line might not exist, or be "SET SCAN ON".
SET SCAN OFF
SET ECHO ON
SET SQLBLANKLINES ON
-- Remember if the scanning was on or off.
PUSH SCAN STATE
SET SCAN ON
UPDATE TABLE_NAME SET CREATED_BY = &&created_by;
-- Revert scanning to its former state.
POP SCAN STATE
行PUSH SCAN STATE
会记住状态,因此如果通过删除第一行来更改代码,则由于相应的POP SCAN STATE
,脚本的其余部分仍可按预期工作。
答案 0 :(得分:1)
sql plus STORE
命令应该这样做,遗憾的是它似乎没有保存SCAN
状态(SQL Plus 9.2.0.1.0)。我将演示另一个设置(TIMING
):
SQL> show timing
timing OFF
SQL> -- save parameters into an os file
SQL> store set param.sql create
Created file param.sql
SQL> -- run script
SQL> SET TIMING ON
SQL> show timing
timing ON
SQL> -- reset state
SQL> @param.sql
SQL> show timing
timing OFF