提示输入变量值时恢复扫描状态

时间:2010-03-11 20:53:58

标签: sql oracle installer database-update

如何检测当前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,脚本的其余部分仍可按预期工作。

1 个答案:

答案 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