ORACLE 将SQL的执行脚本返回值传给SHELL
版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://miracle.blog.51cto.com/255044/70570 |
遇到了一个这样的需求: 用SHELL脚本去调用ORACLE中一个PACKAGE的FUNCTION,根据FUNCTION的返回值,SHELL需要判断接下来的操作。 其实调用一个过程或者函数还是比较简单的,但是捕捉各异的返回值进行判断就稍有不同了。后来我们的原型脚本: sqlplus -S "gsdb/gsdbpass" << ! >/dev/null variable dd number whenever sqlerror exit sql.sqlcode begin :dd := gsdb.pkg_cpms.dbcheck_1('123','67'); raise_application_error(-20224-:dd,'some errors!'); end; / exit; ! export test=$? echo $test 注意:脚本中"$?"可能会因为不同的UNIX或LINUX版本不同而稍有差别。或是$status或是$dd 注意关键的地方: To return a status code of over 0 (which usually indicates no error) up to 255, you can use the "raise_application_error" function, passing -20224-status to it, along with the "whenever sqlerror" directive, to return the code back to the UNIX shell. 好的,我们可以轻松的将SQL脚本执行的返回值让SHELL得到了,但是不要忘记范围:0--255,虽然我们不会用那么多返回值。不难看出ORACLE还有多少这样的小秘密呢 -:) 本文出自 “Be the miracle!” 博客,请务必保留此出处http://miracle.blog.51cto.com/255044/70570 本文出自 51CTO.COM技术博客 |



Larry.Yue
博客统计信息
热门文章
最新评论
友情链接