数据库关联表字段存量数据转移

来源:互联网 发布:eval解析json字符串 编辑:程序博客网 时间:2024/04/28 01:08
#!/bin/sh                                                                             
rm cwsupdate.sql cwsstatis.del
if [ $# -ne 2 ]; then 
    echo "use as ./trans_sh db2name db2passwd"
    exit 1
fi
db2 connect to mbonldb user $1 using $2
db2 set current schema  schema名
db2 "export to cwsstatis.del of del select distinct 字段, 字段,字段 from 表名"
if [ -f cwsstatis.del ];then 
    sed -i "s/\"/'/g" cwsstatis.del
    else
        echo "error!!!db2 export not ok"
        exit 1
fi
awk -F ',' '{print "update 表名 set 字段=" $1 ",字段 =" $2 " where 字段 =\047\047 and字段 =" $3";" >> "cwsupdate.sql"}' cwsstatis.del
if [ -f cwsupdate.sql ];then
    db2 -tvf cwsupdate.sql

    else 

        echo "error!!!awk not ok"
        exit 1
fi



注:单引号用\047代替

0 0