系統環境:centos6.5
oracle版本:oracle11gr2
由於客戶導出的格式是csv格式的,並且數據量比較大,兩千多萬,使用plsql不太合適。考慮使用oracle客戶端工具sqlldr。
如果提供的有表結構最好,直接導入創建表就行了。如果沒有提供,可以先使用wps打開csv文件,根據內容自己去創建表結構。
使用sqlldr有幾種導入方式,這里使用direct直接路徑加並行的模式。
- 先在數據庫創建好空表。
- 創建ctl文件
options(skip=1,columnarrayrows=20971520,ROWS=10000,READSIZE=20971520,ERRORS=999999999) load data infile '/ora11/tmp/zz.csv' append into table "*****_RECORD" fields terminated by ',' Optionally enclosed by '"' (id,record_organ_code,record_organ_name)
1行是導入參數配置,
已經是支持大量數據導入的參數方案。
第3行infile指定導入的文件是USER_INFO.csv;
第4行into table前面的insert表示導入方式:
insert :默認方式,在導入記錄前要求表為空;
append :在表中追加新導入的記錄;
replace :刪除舊記錄(等價delete from table語句),替換成新導入的記錄;
truncate:刪除舊記錄(等價truncate table語句),替換成新導入的記錄;
into table后面指定導入數據庫表USER_INFO,
且表名必須大寫;
第5行指定每一行的字段是以逗號(,)分隔;
第6行指定字段是用兩個分號(')包圍起來的,可選的;
最后一行對應導入的字段,
注意如果導入的是時間字段,
需要指明時間轉換的格式(在這里有坑,要注意格式。本人在實施的過程中已經被坑過了。格式不對會報
SQL*Loader-951: Error calling once/load initialization ORA-02373: Error parsing insert statement for table ESNS."JWXZZ_COVID_RECORD". ORA-00936: missing expression
)。
正確轉換格式寫法
birth_date date "yyyy-mm-dd",
3、使用sqlldr導入
sqlldr userid=esns/***** control=/ora11/tmp/loadfile_csv.ctl direct=true parallel=true
4、導入的相關日志
SQL*Loader: Release 11.2.0.1.0 - Production on Sun Feb 27 23:39:42 2022 Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved. Control File: /ora11/tmp/loadfile_csv.ctl Data File: /ora11/tmp/zz.csv Bad File: /ora11/tmp/zz.bad Discard File: none specified (Allow all discards) Number to load: ALL Number to skip: 1 Errors allowed: 999999999 Continuation: none specified Path used: Direct - with parallel option. Table "JWXZZ_COVID_RECORD", loaded from every logical record. Insert option in effect for this table: APPEND Column Name Position Len Term Encl Datatype ------------------------------ ---------- ----- ---- ---- --------------------- ID FIRST * , O(") CHARACTER RECORD_ORGAN_CODE NEXT * , O(") CHARACTER RECORD_ORGAN_NAME NEXT * , O(") CHARACTER CHILD_CODE NEXT * , O(") CHARACTER CHILD_NAME NEXT * , O(") CHARACTER GENDAR NEXT * , O(") CHARACTER SQL*Loader-281: Warning: ROWS parameter ignored in parallel mode. Table "********_RECORD": 25730788 Rows successfully loaded. 0 Rows not loaded due to data errors. 0 Rows not loaded because all WHEN clauses were failed. 0 Rows not loaded because all fields were null. Bind array size not used in direct path. Column array rows : 10000 Stream buffer bytes: 256000 Read buffer bytes:20971520 Total logical records skipped: 1 Total logical records read: 25730788 Total logical records rejected: 0 Total logical records discarded: 0 Total stream buffers loaded by SQL*Loader main thread: 2786 Total stream buffers loaded by SQL*Loader load thread: 24336 Run began on Sun Feb 27 23:39:42 2022 Run ended on Sun Feb 27 23:43:52 2022 Elapsed time was: 00:04:09.46 CPU time was: 00:02:55.86
參考文檔&感謝:https://blog.csdn.net/bugzeroman/article/details/103031317