How do you pass an argument to a PL/SQL block within a sql file called using START in sqlplus?

ε祈祈猫儿з 提交于 2019-11-28 12:01:29

问题


I have a bash script running several sql files via sqlplus:

sqlplus $connectioninfo << end
start file1.sql
start file2.sql
start file3.sql $variable
quit
end

file3 has some 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:

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:


Try adding SET DEFINE ON to the start of your script 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.



来源:https://stackoverflow.com/questions/15558929/how-do-you-pass-an-argument-to-a-pl-sql-block-within-a-sql-file-called-using-sta

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!