sqlldr 如何匯入一個日期欄位
阿新 • • 發佈:2019-02-19
iamlaosong文
其實很簡單,只要根據原始資料的格式,在控制檔案中欄位名後面加上日期格式字串就行了。例如:
load data
infile '訂單1012-1031.csv'
append into table emsapp_zywl_ddmx
fields terminated by ','
optionally enclosed by '"'
(ddh,xqdh,lsrq date 'YYYY-MM-DD hh24:mi:ss',lsjg,sfj,jsj,wpzl,wptj,wpjs,smjz,psfs,zzfw,mdqx,mdcs,mdsf,sfqx,sfcs,sfsf)
其中lsrq就是日期欄位,內容是日期和24小時制的時間,如:
2017-10-12 15:00:31
這個控制檔案由下面的shell指令碼生成,本指令碼負責將指定目錄下的csv檔案匯入資料庫中:
BAKDIR=/home/oracle/ems_zywl CTLFILE=control.ctl cd ${BAKDIR} for csvfile in *.csv do # process csvfile echo ${csvfile} # read -p "csv file: press enter to continue..." var if [ -f ${csvfile} ]; then # generate control file echo load data>${CTLFILE} echo infile "'"${csvfile}"'">>${CTLFILE} echo append into table emsapp_zywl_ddmx>>${CTLFILE} echo fields terminated by "','">>${CTLFILE} echo optionally enclosed by "'\"'">>${CTLFILE} echo "(ddh,xqdh,lsrq date 'YYYY-MM-DD hh24:mi:ss',lsjg,sfj,jsj,wpzl,wptj,wpjs,smjz,psfs,zzfw,mdqx,mdcs,mdsf,sfqx,sfcs,sfsf)">>${CTLFILE} # import data sqlldr userid=emssxjk/emssxjk control=control.ctl skip=1 mv ${csvfile} all_csv fi done