- 论坛徽章:
- 1
|
aaa.txt内容为
张三 001
李四 002
王五 003
gzb表内容
bianhao gongzi
---------------------------------
001 100.00
002 200.00
003 200.00
004 150.00
006 200.00
1、111.sh
#!/bin/ksh
source /home/db2inst1/sqllib/db2profile
db2 "connect to abcdb user www using www"
cat aaa.txt|while read A B
do
C=`db2 -x "select gongzi from gzb where bianhao=‘$B’" `
echo $A,$B,$C >> bbb.txt
done
2、222.sh
#!/bin/ksh
source /home/db2inst1/sqllib/db2profile
cat aaa.txt|while read A B
do
db2 "connect to abcdb user www using www"
C=`db2 -x "select gongzi from gzb where bianhao=‘$B’" `
echo $A,$B,$C >> bbb.txt
done
用第一种方法:会报错 数据库链接不存在
用第二种方法:操作成功,但是会在while do循环中不停的链接数据库
运行结果:
bbb.txt内容
张三,001,100
李四,002,200
王五,003,200
求助各位大神,为什么在shell中 数据库连接操作在do while 循环外不可用呢 |
|