加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Shell脚本嵌入Oracle PL / SQL代码定义绑定变量

发布时间:2020-12-15 21:48:13 所属栏目:安全 来源:网络整理
导读:如果我运行以下脚本,我收到错误 SP2-0552:绑定变量“OUTRES”未声明. 那么,如何定义绑定变量OUTRES以及在何处定义? #!/usr/bin/bashsqlplus -s scott/tiger EOF declare ret varchar2(10):= '0';begin begin insert into mytab(col1) values(1); exception
如果我运行以下脚本,我收到错误
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

解决方法

如果要在sqlplus中声明绑定变量.使用VAR关键字.

sqlplus -s scott/tiger << EOF 
VAR OUTRES NUMBER;
BEGIN
  NULL; /* Your Statements */
END;
/
EOF

您也可以尝试退出: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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读