如果我运行下面的脚本,我会得到错误 SP2-0552:未声明绑定(bind)变量“OUTRES”。 那么,如何定义绑定(bind)变量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
最佳答案
如果要在sqlplus
中声明绑定(bind)变量。使用 VAR
关键字。
sqlplus -s scott/tiger << EOF
VAR OUTRES NUMBER;
BEGIN
NULL; /* Your Statements */
END;
/
EOF
你也可以试试 quit :OUTRES
和
quit :OUTRES
EOF
MYRESULT=$?
echo $MYRESULT
在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
关于sql - 嵌入定义绑定(bind)变量的 Oracle PL/SQL 代码的 Shell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21251630/