shell脚本嵌入的Oracle PL / SQL code定义绑定变量 [英] Shell script embedding Oracle PL/SQL code defining bind variable

查看:771
本文介绍了shell脚本嵌入的Oracle PL / SQL code定义绑定变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我运行下面的脚本,我得到错误
SP2-0552:绑定变量OUTRES未声明
那么,如何定义绑定变量OUTRES和在哪里定义?

 #!的/ usr /斌/庆典
SQLPLUS -s斯科特/老虎<< EOF
声明RET VARCHAR2(10):='0';
开始
  开始
    插入编辑MyTAB(COL1)的值(1);
  例外
    别人那么当
      RET:RET = ||'1';
  结束;
  选择RET成:从双OUTRES;
结束;
/
放弃
EOF


解决方案

如果你想在声明 SQLPLUS 绑定变量。使用 VAR 关键字。

 的sqlplus -s斯科特/老虎<< EOF
VAR OUTRES数;
开始
  空值; / *您的语句* /
结束;
/
EOF

您也可以尝试退出:OUTRES

 退出:OUTRES
EOF
MYRESULT = $?
回声$ MYRESULT

据输出 UNIX

的返回状态

 #!的/ usr /斌/庆典
SQLPLUS -s斯科特/老虎<< EOF
VAR OUTRES数;
声明RET VARCHAR2(10):='0';
开始
  开始
    EXECUTE IMMEDIATE'插入编辑MyTAB(COL1)VALUES(1);
  例外
    别人那么当
      DBMS_OUTPUT.PUT_LINE(SQLERRM);
      RET:RET = ||'1';
  结束;
  :OUTRES:= RET;
结束;
/
退出:OUTRES
EOF
MYRESULT = $?
回声$ MYRESULT

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?

#!/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

解决方案

If you want to declare the bind variable in sqlplus. use the VAR keyword.

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

You can also try quit :OUTRES and

quit :OUTRES
EOF
MYRESULT=$?
echo $MYRESULT

It output the return status in 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

这篇关于shell脚本嵌入的Oracle PL / SQL code定义绑定变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆