The DB2 tutorial you are looking at is: Use shell extraction to update DB2 data. The shell processing DB2 database, which is written for work needs, extracts DB2 data from the shell and processes it.
#SQL文定义
Sql= "SELECT AAA, BBB, CCC from MYTBL1"
#执行SQL
Sdata= ' DB2 ' "$SQL"
#返回值判断
If [$?-ne 0]
Then
#显示db2返回的错误信息
echo "$SDATA"
Exit 1
Fi
#对取得的数据进行处理.
echo "$SDATA" | Sed-e ' 4,/^$/!d;/^$/d ' |
While read AAA triple BBB CCC
Todo
echo "AAA is $AAA, the BBB is $BBB, the CCC is $CCC"
Done
#取得数据件数
echo "$SDATA" | Sed-n-E '/^$/{1,3d;n;s/[^0-9]*\ ([0-9]*\) [^0-9]*/\1/;p;} ' | Read CNT
echo "The Count of selected data is $CNT."
Exit 0★ update DB2 data and get updated results
Sql= "UPDATE MYTBL1 SET aaa= ' in ', bbb= ', ccc= ' 12 '"
#执行SQL
Sdata= ' db2-a ' "$SQL"
#取得SQLCODE
echo "$SDATA" | Sed-n-E ' s/^.*sqlcode: \ ([-,0-9][0-9]*\). */\1/p ' | Read SQLCODE
echo "Sqlcode is $SQLCODE."
#取得SQLSTATE
echo "$SDATA" | Sed-n-E ' s/^.*sqlstate: \ ([-,0-9][0-9]*\). */\1/p ' | Read SQLSTATE
echo "Sqlstate is $SQLSTATE."
#取得更新件数 (that is, the third value of SQLERRD)
echo "$SDATA" | Sed-n-E '/sqlerrd/s/^.* (3) \ ([-,0-9][0-9]*\). */\1/p ' | Read updcnt
echo "Updated data ' s count is $UPDCNT."
#取得sqlerrd的第五个值
echo "$SDATA" | Sed-n-E '/sqlerrd/{n;s/^.* (5) \ ([-,0-9][0-9]*\). */\1/;p;} ' | Read SQLERRD5
echo "SQLERRD (5) is $SQLERRD 5."