获取ksh中SQL函数的返回值

时间:2015-08-25 16:40:18

标签: sql shell unix plsql ksh

我使用KSH调用SQL函数。根据函数的输出/返回值,我想做一些检查,但首先我需要访问该值。

这是我的KSH代码/功能:

# Call runSeriatimValuation Web Service
runSeriatimValuation() {

  jobNum=$1
  echo "Running Seriatim Valuation with ${jobNum}"

  # Call web service Oracle stored procedure
  ${sqlplusCmd} << END_SQLPLUS  
   WHENEVER SQLERROR EXIT SQL.SQLCODE ROLLBACK;
   WHENEVER OSERROR EXIT 9 ROLLBACK;
   DECLARE
    v_Return INT;
   BEGIN
    v_Return := CALL_IPVFBJAVA_WEBSERVICE(${jobNum});
    COMMIT;
   END;
   /
END_SQLPLUS

# This is the return value of the SQL command above if it was 
# successfully execute or not. Its not related to v_Return.

 errorCode=$?

 # If error, handle and exit
 if [ "${errorCode}" -ne "0" ] ; then
   echo "Error (${errorCode}) occurred in runSeriatimValuation when calling procedure"
   exitAgent 1
 fi

# **** Here I would like to do my if/else checking on v_Return, How can I do that ???? ***** 
# how can I assign v_Return to a variable of type int and check the value of it.

 return 0
}

谢谢 - 非常感谢您的帮助。

2 个答案:

答案 0 :(得分:0)

您可以直接查看下面的返回类型,

if [ $? -eq 0 ]
then
##DO Something
else
##DO Something
fi

答案 1 :(得分:0)

您可以做的是设置变量并将其等同于sql命令。

例如:

var1=${sqlplusCmd} << END_SQLPLUS  
WHENEVER SQLERROR EXIT SQL.SQLCODE ROLLBACK;
WHENEVER OSERROR EXIT 9 ROLLBACK;
select CALL_IPVFBJAVA_WEBSERVICE(${jobNum}) from dual;
commit
exit;
END_SQLPLUS
相关问题