用shell抽取,更新db2的数据
正在看的db2教程是:用shell抽取,更新db2的数据。为工作需要而写的shell处理db2数据库的程序用shell抽取db2的数据,并进行处理。
#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 BBB CCC
do
echo "AAA IS $AAA, BBB IS $BBB, 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★更新db2的数据,并取得更新结果
SQL="UPDATE MYTBL1 SET AAA='2005',BBB='05',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."
#取得更新件数(即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 $SQLERRD5."
#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 BBB CCC
do
echo "AAA IS $AAA, BBB IS $BBB, 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★更新db2的数据,并取得更新结果
SQL="UPDATE MYTBL1 SET AAA='2005',BBB='05',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."
#取得更新件数(即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 $SQLERRD5."
相关推荐
tianhuak 2020-11-24
huha 2020-10-16
lianshaohua 2020-09-23
laisean 2020-11-11
zhangjie 2020-11-11
大牛牛 2020-10-30
firefaith 2020-10-30
liguojia 2020-10-20
wangzhaotongalex 2020-10-20
以梦为马不负韶华 2020-10-20
CARBON 2020-10-20
彼岸随笔 2020-10-20
lianshaohua 2020-10-20
yutou0 2020-10-17
JohnYork 2020-10-16
xiaonamylove 2020-10-16
Julyth 2020-10-16
applecarelte 2020-10-16
ourtimes 2020-10-16