本文共 2164 字,大约阅读时间需要 7 分钟。
示例:
OUT_MSG=$(db2 -v "call liao.proc1('${PAR1}','${PAR2}',?)" )
CMDRET=$?OUTRET=$(echo "$OUT_MSG" | awk '/Parameter Name/ {PAR=$4} /Parameter Value/ {VAL=$4} /^$/ {if (PAR == "O_RETURN") print VAL}')db2 - 如何在shell中获取存储过程OUT型参数的返回值create or replace procedure liao.proc1( in I_PARAM1 varchar(10) ,in I_PARAM2 varchar(10) ,out O_RETURN integer)specific liao.proc1language sqlbegin set O_RETURN=123;end@OUT_MSG=$(db2 -v "call liao.proc1('${PAR1}','${PAR2}',?)" )CMDRET=$?#注意这里的$OUT_MSG要用双引号括起否则echo出来后换行符会丢失,还有因为是匹配Parameter所以要在英文环境OUTRET=$(echo "$OUT_MSG" | awk '/Parameter Name/ {PAR=$4} /Parameter Value/ {VAL=$4} /^$/ {if (PAR == "O_RETURN") print VAL}')if [ $CMDRET -ne 0 -o $OUTRET -ne 0 ]; echo "ERROR..."fi
参考:
Hi experts,
This should be the simple question. I am calling db2 stored procedure having output parameter from the command prompt. How to display (ECHO) the output parameter value of the stored procedure at the command prompt? ThanksFROM: https://www.experts-exchange.com/questions/22966982/DB2-Stored-Procedure-Output-Value-Command-Prompt.html
转载地址:http://lktai.baihongyu.com/
Accepted Solution on 2007-11-18 at 12:37:43
Hi ajexpert,
I can give an example, but I'm not sure it will help, since you are working in a Windows environment. But in case you are familiar with both DOS batch scripting and Unix shell scripting, maybe you can use my shell script as an example to create a DOS batch. Create a executable file named "get_param_value" that contains: /usr/bin/awk -v P=$1 ' /Parameter Name/ { PARAM=$4 } /Parameter Value/ { VAL=$4 } /^$/ { if( PARAM == P ) print VAL }' What this awk script does is look for a parameter that you pass into this script. When the awk script finds the variable, it finds the value on the next line, then when it encounters the next blank line, it outputs the value if we found the param name. So, if you use the stored procedure I put in my first post, you can do this: $ db2 "call test(5,6,?) | ./get_param_value P_OUT In this case, it would print just the value 11. Sorry again that this is Unix, but I'm not sure how to do a Windows equivalent. Keith