oracle 如何将参数传递给 sqlplus 中使用 START 调用的 sql 文件中的 PL/SQL 块?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15558929/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do you pass an argument to a PL/SQL block within a sql file called using START in sqlplus?
提问by xdhmoore
I have a bash script running several sql files via sqlplus:
我有一个通过 sqlplus 运行多个 sql 文件的 bash 脚本:
sqlplus $connectioninfo << end
start file1.sql
start file2.sql
start file3.sql $variable
quit
end
file3 has some PL/SQL:
file3 有一些 PL/SQL:
BEGIN
DBMS_OUTPUT.PUT_LINE(&1);
END;
/
But it just prints the literal "&1"
instead of the value of $variable
. I have also tried the following in file3:
但它只是打印文字"&1"
而不是$variable
. 我还在 file3 中尝试了以下内容:
DEFINE var_a = &1;
BEGIN
DBMS_OUTPUT.PUT_LINE(var_a);
END;
/
and also the following:
以及以下内容:
DECLARE
var_b VARCHAR2(64) := &1;
BEGIN
DBMS_OUTPUT.PUT_LINE(var_b);
END;
/
and finally:
最后:
DEFINE var_a = &1;
DECLARE
var_b VARCHAR2(64) := var_a;
BEGIN
DBMS_OUTPUT.PUT_LINE(var_b);
END;
/
However, I am getting various errors or just the literal value '&1' for all of these.
但是,我收到了各种错误,或者只是所有这些的字面值“&1”。
回答by Luke Woodward
Try adding SET DEFINE ON
to the start of your script file3.sql
.
尝试添加SET DEFINE ON
到脚本的开头file3.sql
。
If SET DEFINE
is ON
, SQL*Plus will replace &...
substitution parameters with their values. If SET DEFINE
is OFF
(which it seems to be for you), SQL*Plus won't do this.
如果SET DEFINE
是ON
,SQL*Plus 将&...
用它们的值替换替换参数。如果SET DEFINE
是OFF
(它似乎适合您),则 SQL*Plus 不会这样做。