在shell指令碼中,向oracle資料庫表插入資料
要先確認環境是否有sqlldr命令
"編碼","訂購狀態","產品編碼","產品訂購例項id","訂購生效時間","訂購失效時間","計費開始時間","受理工號","bboss商品名稱","商品規格編碼","商品例項id","產品名稱","產品規格編碼","產品訂購例項id"
"3511143538","0","111601","9004714567","20181229170033","20991231235959","20181229170033","351afikln@@351","","","","","",""
"3526218531","0","111601","9004704255","20181227111850","20991231235959","20181227111850","351gkka9m@@351","","","","","",""
"3510068521","0","111789","9004703175","20181226205029","20991231235959","20181226205029","bbss_ecopinter","","","","","",""
"3513509860","0","111800","9004702728","20181226183348","20991231235959","20181226183348","351glf7yk@@351","","","","","",""
"3521168039","0","111716","9004702545","20181226173146","20991231235959","20181226173146","bbss_ecopinter","","","","","",""
load data characterset zhs16gbk
infile '******.csv'
truncate into table table_name
fields terminated by "," optionally enclosed by '"' trailing nullcols
( customernumber enclosed by '"',
state enclosed by '"',
prodid enclosed by '"',
productid enclosed by '"' ,
effdate enclosed by '"' "to_date(:effdate, 'yyyymmddhh24miss')",
expdate enclosed by '"' "to_date(:expdate, 'yyyymmddhh24miss')",
zfjfdate enclosed by '"' "to_date(:zfjfdate, 'yyyymmddhh24miss')",
login_no enclosed by '"',
bboss_goods_name enclosed by '"',
bboss_goods_attrcode enclosed by '"',
bboss_goods_productid enclosed by '"',
bboss_prod_name enclosed by '"',
bboss_prod_attrcode enclosed by '"',
bboss_prod_productid enclosed by '"',
op_time sysdate
)
infile:需要匯入的資料檔名+路徑txt或者csv格式
truncate:插入資料的方式
insert:空表插入,非空報錯
replace:替換,先刪除(delete)表資料,再插入
truncate:替換,先刪除(truncate)表資料,再插入
into table pd_order_info_temp:目標的表名
fields terminated by "," 表示【infile】列值使用","進行分割
optionally enclosed by '"' 表示【infile】中列值使用""包裹
trailing nullcols:如要匯入原始檔此列內容為空,在匯入到表中時,此列內容就是null
( ........) :括號內為目標表裡的欄位名,對於date和timestamp的資料型別需要注意,需要轉一下資料型別
當通過sqlldr匯入資料txt檔案時,每個欄位的最大值不能超過255,當資料庫中原有資料長度超過255時,需要在控制檔案中將這個欄位char(2000)
(d1 ,
d2 char(2000)
)
sqlldr user/password@資料庫名 control=***x.ctl skip=1 load=200000 errors=100 rows=1000 bindsize=33554432 bad=e:/bad.bad log = e:/ log.log
user/password //資料庫的使用者名稱密碼
control //sqlldr控制檔案位置
skip=1 //表示跳過第一行,從第二行開始匯入
load=200000 //表示並不匯入所有的資料,只匯入跳過skip引數後的200000條資料
rows=1000 //表示一次載入的行數,預設值為64,此處設定為1000
errors=100 //表示出錯100次後,停止載入
bindsize=33554432 //表示每次提交記錄緩衝區的大小,預設256k
bad = e:/bad.bad --- 當匯入檔案出錯時就會在 e盤生成.bad 的檔案 , 裡面會記錄你出錯誤沒有匯入的資料
log = e:/log.log -- 當匯入檔案 , 會記錄你匯入檔案詳細的內容 , 包括出錯的資訊
Shell中fork source exec的區別
fork是linux的系統呼叫,用來建立子程序,子程序是父程序的乙個副本,從父程序那裡獲得一定的資源分配以及繼承父程序的環境。子程序與父程序唯一不同的地方在於pid process id 環境變數 傳給子程序的變數,遺傳性是本地變數和環境變數的根本區別 只能單向從父程序傳給子程序。不管子程序的環境變...
shell指令碼中的函式, shell中的陣列
示例1 bin bash 函式的使用 input input 1 a b root second fun.sh 1 a 3 fun.sh 示例2 bin bash 傳遞乙個引數給函式 input read p please input n input root second fun.sh pleas...
shell中豎線的作用 Shell中符號意義
末端 end of line 這個常用在 grep sed awk 以及 vim vi 當中。變數的正規表示式 bash 對 定義了不少用法。見本文後部 引用script 的執行引用變數 引用引數的演算法與一般指令相同,指令本身為0,其後為1,然後依此類推。引用變數的代表方式如下 0,1,2,3,4...