Use shell extraction to update DB2 data _DB2

Source: Internet
Author: User
Tags db2
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."

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.