csv格式的数据导⼊到oracle数据库
系统环境:centos6.5
oracle版本:oracle11gr2
由于客户导出的格式是csv格式的,并且数据量⽐较⼤,两千多万,使⽤plsql不太合适。考虑使⽤oracle客户端⼯具sqlldr。
如果提供的有表结构最好,直接导⼊创建表就⾏了。如果没有提供,可以先使⽤wps打开csv⽂件,根据内容⾃⼰去创建表结构。使⽤sqlldr有⼏种导⼊⽅式,这⾥使⽤direct直接路径加并⾏的模式。
1. 先在数据库创建好空表。
2. 创建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"yy-mm-dd",
3、使⽤sqlldr导⼊
sqlldr userid=esns/***** control=/ora11/tmp/l direct=true parallel=true
4、导⼊的相关⽇志
SQL*Loader: Release 11.2.0.1.0 - Production on Sun Feb 2723:39:422022
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
Control File:  /ora11/tmp/l
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 2723:39:422022
Run ended on Sun Feb 2723:43:522022
plsql developer导入数据
Elapsed time was:    00:04:09.46
CPU time was:        00:02:55.86

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。