我有一个具有以下语句的sql文件:
BEGIN
if (&&masterKey = 1) then
shutdown immediate;
startup restrict;
end if;
END;
/
在另一个SQL文件(defineVariables.sql)中,我声明了变量masterKey。
DEFINE masterKey = 0;
并在这里使用导入的SQL
@defineVariables.sql
在执行脚本时,出现以下错误。我不确定是否因为我使用了shutdown语句?有人可以帮我这个查询吗?
错误信息:
SQL> BEGIN
2 if (&&masterKey = 1) then
3 shutdown immediate;
4 startup restrict;
5 end if;
6 END;
7 /
old 2: if (&&masterKey = 1) then
new 2: if (0 = 1) then
shutdown immediate;
*
ERROR at line 3:
ORA-06550: line 3, column 10:
PLS-00103: Encountered the symbol "IMMEDIATE" when expecting one of the
following:
:= . ( @ % ;
ORA-06550: line 5, column 1:
PLS-00103: Encountered the symbol "END" when expecting one of the following:
begin function pragma procedure subtype type <an identifier>
<a double-quoted delimited-identifier> current cursor delete
exists prior
最佳答案
您不能在PLSQL中执行此操作,因为“立即关闭”不是PLSQL或SQL命令,而是SQLplus命令。该问题的答案描述了一种有条件执行脚本的方法:
SQLplus decode to execute scripts
基本上,根据您的主键的值,您可以选择两个脚本名称之一,然后以该名称执行脚本。
基于前面示例中的代码。
sql> variable flag varchar2(7);
sql> exec :flag := '&&masterKey';
sql> column our_script new_value script noprint;
sql> select decode(:flag, '1',
'c:\sqlplus\shutdown_script.sql',
'c:\sqlplus\do_not_shutdown.sql'
) our_script
from dual;
执行
sql> @&script;
shutdown_script将是
prompt shutting down
shutdown immediate;
do_not_shutdown脚本是
prompt Not shutting down
关于sql - Oracle SQL中的脚本错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39701508/