bash Shell 脚本嵌入 Oracle PL/SQL 代码定义绑定变量
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21251630/
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
Shell script embedding Oracle PL/SQL code defining bind variable
提问by Ibrahim Quraish
If I run the below script, I am getting the error SP2-0552: Bind variable "OUTRES" not declared.So, how to define the bind variable OUTRES and where to define?
如果我运行以下脚本,则会收到错误 SP2-0552:未声明绑定变量“OUTRES”。那么,如何定义绑定变量OUTRES以及在哪里定义呢?
#!/usr/bin/bash
sqlplus -s scott/tiger << EOF
declare ret varchar2(10):= '0';
begin
begin
insert into mytab(col1) values(1);
exception
when others then
ret:=ret||'1';
end;
select ret into :OUTRES from dual;
end;
/
quit
EOF
回答by Maheswaran Ravisankar
If you want to declare the bind variable in sqlplus
. use the VAR
keyword.
如果要在sqlplus
. 使用VAR
关键字。
sqlplus -s scott/tiger << EOF
VAR OUTRES NUMBER;
BEGIN
NULL; /* Your Statements */
END;
/
EOF
You can also try quit :OUTRES
and
您也可以尝试quit :OUTRES
和
quit :OUTRES
EOF
MYRESULT=$?
echo $MYRESULT
It output the return status in UNIX
.
它在 中输出返回状态UNIX
。
#!/usr/bin/bash
sqlplus -s scott/tiger << EOF
VAR OUTRES NUMBER;
declare ret varchar2(10):= '0';
begin
begin
EXECUTE IMMEDIATE 'insert into mytab(col1) values(1)';
exception
when others then
dbms_output.put_line(SQLERRM);
ret:=ret||'1';
end;
:OUTRES := ret;
end;
/
quit :OUTRES
EOF
MYRESULT=$?
echo $MYRESULT
回答by A Nice Guy
#!/usr/bin/bash
sqlplus -s scott/tiger << EOF
declare
ret varchar2(10):= '0';
OUTRES varchar2(10);
begin
begin
insert into mytab(col1) values(1);
exception
when others then
ret:=ret||'1';
end;
select ret into OUTRES from dual;
dbms_output.put_line('Value of OUTRES is' || OUTRES);
end;
/
quit
EOF