Shell执⾏DB2SQL返回值
Shell代码
1. #!/usr/bin/env sh
2.
3. DBNODE='nodename'
4. DBUSER='username'
5. DBPASSWORD='password'
6.
7.
8. connDB2()
9. {
10. if( db2 connect to $1 user $2 using $3 > /dev/null )
11. then
12. echo 'OK'
13. else
14. echo "failed connect to ${DBNODE}"
15. exit -1
16. fi
17. }
18.
19. releaseDB2(){
20. db2 connect reset > /dev/null
21. }
22.
23. run(){
24. connDB2 ${DBNODE} ${DBUSER} ${DBPASSWORD}
25. sql="
26. select
27. area_id ,areaname
28. from
29. pt.area
30. "
31.
32. db2 -x ${sql}| while read area_id areaname
33. do
34. echo "Result:${area_id}->${areaname}"
35. done
36. releaseDB2
37. }
38.
39. echo "execute sql ................."
40. run
如果有必要可以通过执⾏完SQL后$?的结果来判断是不是执⾏成功
Shell代码
db2数据库sql语句
1. if [ "$?" -ne "0" ]
2. then echo "execute error"
3. exit -1
4. fi
下⾯是DB2⽂档中到的返回值的含义
The return code can be one of the following:
Code Description
0 DB2 command or SQL statement executed successfully
1 SELECT or FETCH statement returned no rows
2 DB2 command or SQL statement warning
4 DB2 command or SQL statement error
8 Command line processor system error
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论