bash 从 Shell 脚本执行 PL SQL 过程

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28302888/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 12:19:12  来源:igfitidea点击:

execute PL SQL Procedure from Shell Script

bashshellunixplsql

提问by Soyf

Hi I'm trying to execute PL SQL Procedure from my Shell Script and get the return value (out value), but it's not working. Can anyone advise what I'm doing wrong? Here's what I have:

嗨,我正在尝试从我的 Shell 脚本执行 PL SQL 过程并获取返回值(输出值),但它不起作用。谁能建议我做错了什么?这是我所拥有的:

output="$(sqlplus -S user/pw@//ip:1521/db <<ENDOFSQL
set serveroutput on;
DECLARE
    v_return PLS_INTEGER;
BEGIN
    PKG.Procedure(v_return);
    DBMS_OUTPUT.PUT_LINE(v_return);
END;
exit;
ENDOFSQL)"

echo $output 

回答by Soyf

After a long day of trial and error I finally got it working with the below script:

经过一整天的反复试验,我终于用下面的脚本让它工作了:

#!/bin/ksh

CODE=`sqlplus -S $SCHEMA/$PW@//$IP_PORT/$DB << EOM
Set timing on
Set serveroutput on
Whenever sqlerror exit failure;
Whenever  oserror exit failure;
declare
v_return number;
begin
PKG.Procedure(v_return);
end;
/
EOM`

if [ $? != 0 ]
then
 echo  "process failed."
 exit 1
fi

exit $?