博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
db2 - 如何在shell中获取存储过程OUT型参数的返回值(awk)
阅读量:4177 次
发布时间:2019-05-26

本文共 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

参考:

DB2 Stored Procedure Output Value Command Prompt

Question by:
On

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?
Thanks

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

FROM: https://www.experts-exchange.com/questions/22966982/DB2-Stored-Procedure-Output-Value-Command-Prompt.html

转载地址:http://lktai.baihongyu.com/

你可能感兴趣的文章
最新:斐讯K3千兆无线路由器刷官改版固件的详细图文教程
查看>>
Windows基于Apache的svn服务器配置
查看>>
不偏移的天地图地图服务-ArcGIS版
查看>>
cesium调用天地图服务
查看>>
objTo3d-tiles:将obj模型文件转换为三维瓦片
查看>>
Linux查看硬件信息命令
查看>>
.obj 和 .mtl文件格式
查看>>
CentOS6.5 添加开机自启动脚本
查看>>
转载:百度网盘下载速度提高100倍
查看>>
(转)在Mac系统下发布Qt程序详细教程
查看>>
VC++操作Excel文档的方法,读取,查询,写入,修改,删除
查看>>
Access 和vc6.0 相连,在我indows64 位系统中,出现找不到Microsoft Access Driver(*.mdb) ODBC驱动程序的安装例程。请重新安装驱动
查看>>
C# 获取指定目录下所有文件信息、移动目录、拷贝目录
查看>>
C#文件操作大全
查看>>
算法-计算无向图中两个节点之间所有的路径
查看>>
转载:SDE ST_Geometry SQL st_intersects查询很慢的解决方法
查看>>
Spring框架的基本概念
查看>>
Spring框架的IoC容器详解
查看>>
JSF的ManagedBean与Spring Bean的比较与集成
查看>>
Spring Bean的延迟初始化
查看>>