• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

freetds操作sqlserver ,执行sql, load数据, zli

未分类 wangting 2年前 (2017-07-27) 359次浏览

执行

db_server=’192.168.145.xxx’;
db_username=’dbname’;
db_password=’dbpassword’;
db_table=”media.dbo.tablename”;

echo “入库前删除”
sql=”delete from media.dbo.t_mcm_k_score_day where day_key=’$dt’ ”
echo “[INFO] $sql”

 

 

 

入库load数据
echo “/usr/local/freetds/bin/freebcp \”$db_table\” in \”$resultpath/result.txt\” -S $db_server -U $db_username -P $db_password -c”
/usr/local/freetds/bin/freebcp “$db_table” in “$resultpath/result.txt” -S $db_server -U $db_username -P $db_password -c[/dangerbox]

 

 

查询结果,并判断

echo “检查库中是否有数”
sql_check=”select
count(1)
from t_zm_lvl_everymonth
where import_date =DATEADD(day,1,’${dt}’) ”

echo “sql_check: ” $sql_check

res=0
for((i=1;i<=6;i++));
do
res=`
/usr/local/freetds/bin/bsqldb -U $db_username -P $db_password -S $db_server -D media <<EOF
${sql_check}
EOF
`
echo “____[INFO] 第${i}次检查:t_zm_lvl_everymonth,共有${res}条数据!”

if [ ${res} == 0 ]
then sleep 300
else
i=10
fi
done

if [ $res == 0 ]
then
echo “____[WARING] t_zm_lvl_everymonth!”
exit 255
fi
echo “____[INFO] t_zm_lvl_everymonth,共有${res}条数据!”

 

 

 

1,按表导出
/usr/local/freetds/bin/freebcp tb1 out tb1.txt -S ssgg -U ssgg -P ssgg -c
2,按查询导出
/usr/local/freetds/bin/freebcp “select * from xxx.[xxx].tb1” queryout /home/oracle/tb1.txt -c -t “|” -S 192.100.251.218 -U sa -P 11
如果不设置字符集会出现:
Some character(s) could not be converted into client’s character set.  Unconverted bytes were changed to question marks (‘?’)


喜欢 (1)