sqlldr从服务器上获取txt文件数据导入到数据库

1、需求:
从指定服务器上获取txt文件数据,导入指定到数据库中


2.  INTERFACE_test_LABEL.ctl 文件内容如下:
load data
CHARACTERSET UTF8
#要读取的文件
infile '/ test _cpcout / test /test_20170811_000001.txt'
append into table TBL_test_BASE_INFO
fields terminated by X'1'
TRAILING NULLCOLS
(
user_name            "decode(:user_name            ,'\\N',null,'--',null,:user_name           )",
age                  "decode(:age                  ,'\\N',null,'--',null,:age                 )",
sex                  "decode(:sex                  ,'\\N',null,'--',null,:sex                 )",
user_id              "decode(:user_id              ,'\\N',null,'--',null,:user_id             )",
create_date  "to_char(sysdate,'YYYYMMDDHH24MISS')",
id "sys_guid()"
)


3、test.sh脚本如下执行命令如下:  
#!/bin/bash
. $HOME/.bash_profile
cd /test_cpcout/test;
v_out_path="/test_cpcout/test/";
v_out_file="test_"`date -d "+0 day" "+%Y%m%d"`;
v_file_new=$(find $v_out_path$v_out_file*|head -1);
#v_file_name=$(basename $v_file_new .txt);

#v_file=$(find /holly_cpcout/test/ -name test_`date -d "+0 day" "+%Y%m%d"`_*|head -1)
echo $v_file_new
#count=`awk '{print NR}' $v_file_new|tail -n1`
#if [ "$count" > "0" ]; then 
if [  -f "$v_file_new" ]; then 
echo "load data" >INTERFACE_test_LABEL.ctl;
echo "CHARACTERSET UTF8">>INTERFACE_test_LABEL.ctl;
echo "infile '"$v_file_new"'">>INTERFACE_test_LABEL.ctl;
echo "append into table TBL_test_BASE_INFO">>INTERFACE_test_LABEL.ctl;
echo "fields terminated by X'1' ">>INTERFACE_test_LABEL.ctl;
echo "TRAILING NULLCOLS">>INTERFACE_test_LABEL.ctl;
echo "(
user_name            \"decode(:user_name            ,'\\\N',null,'--',null,:user_name           )\",
age                  \"decode(:age                  ,'\\\N',null,'--',null,:age                 )\",
sex                  \"decode(:sex                  ,'\\\N',null,'--',null,:sex                 )\",
user_id              \"decode(:user_id              ,'\\\N',null,'--',null,:user_id             )\",
create_date  \"to_char(sysdate,'YYYYMMDDHH24MISS')\",
id \"sys_guid()\"
)">>INTERFACE_test_LABEL.ctl;

sqlldr test/test@127.0.0.1:1521/wxclyy  control=INTERFACE_test_LABEL.ctl direct=true log=error.log errors=1000 rows=30000;

mv $v_file_new $v_out_path/test_history/;

else 
echo "file is empty!"
fi
exit;


4、执行sh脚本,即可导入
   ./holly_cpcout/test/test.sh




  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值