【发布时间】:2015-11-19 11:36:15
【问题描述】:
我正在使用 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
}
谢谢 - 非常感谢您的帮助。
【问题讨论】:
-
您应该将
if [ "${errorCode}" -ne "0" ]更改为if [ ${errorCode} -ne 0 ](比较整数)或if [ "${errorCode}" != "0" ](比较字符串)。我不知道这是否能回答所有问题,您能否在 if 语句之前echo "errorCode=${errorCode}"并使用正确和不正确的代码进行测试(将COMMIT更改为AJR)。 -
谢谢 - 好收获。但是如何检查 v_Return 值?
-
你能在
COMMIT之后做类似EXIT v_Return的事情吗?也许用EXIT 42进行测试,这样你就会得到一个清晰的返回码。