我有一个CSV文件,我试图使用SQL * Loader加载到Oracle表中:
a, ab, abcdefg
b, bc, bcdefghij
c, cd, cdefghijk-lmnop
orstuv
wxyz
d, de, defghijk
在行" c"第3列有多行,当我们用sqlldr
加载这一行时,它无法将该列加载到表中 - 它将它放入坏文件中。
我试图为这个列
包含引号字符串a, ab, "abcdefg"
b, bc, "bcdefghij"
c, cd, "cdefghijk-lmnop
orstuv
wxyz"
d, de, "defghijk"
我尝试了多种格式的控制文件,包括:
load data
CHARACTERSET TH8TISASCII
infile '/data/csv/test3.txt'
APPEND
PRESERVE BLANKS
into table ITEM
fields terminated by ","
TRAILING NULLCOLS
( col1,
col2,
col3,
col4)
和
load data
CHARACTERSET TH8TISASCII
infile '/data/csv/test3.txt' "str '\n'"
APPEND
PRESERVE BLANKS
into table ITEM
fields terminated by ","
TRAILING NULLCOLS
( col1,
col2,
col3,
col4)
和
load data
CHARACTERSET TH8TISASCII
infile '/data/csv/test3.txt'
APPEND
PRESERVE BLANKS
into table ITEM
fields terminated by "," optionally enclosed by '"'
TRAILING NULLCOLS
( col1,
col2,
col3,
col4)
和
load data
CHARACTERSET TH8TISASCII
infile '/data/csv/test3.txt'
APPEND
PRESERVE BLANKS
into table ITEM
fields terminated by "," optionally enclosed by '\n'
TRAILING NULLCOLS
( col1,
col2,
col3,
col4)
但它仍然无效。
如何从CSV格式加载数据?
据Gary_W推荐 我试图添加" str x' 0D'"并且数据可以正确加载到列中 但它只加载CSV文件的第一行并成功返回日志,如下所示
load data
CHARACTERSET TH8TISASCII
infile '/data/csv/b.csv' "str x'0D'"
APPEND
PRESERVE BLANKS
into table ITEM2
fields terminated by "," optionally enclosed by '"'
TRAILING NULLCOLS
( col1,
col2,
col3,
col4
)
--Sample CSV file
c, cd, "cdefghijk-lmnop
orstuv
wxyz"
,c
a, ab, "abcdefg", a
b, bc, "bcdefghij", b
d, de, "defghijk",d
--sql loader command
sqlldr USER/PASSWORD readsize=2000000000 bindsize=2000000000 control=file_pointing2.ctl > /data/csv/sqlldr.log
###########################LOG########################
Table ITEM:
1 Row 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.
there have only 1 record.
###########################OUT_PUT########################
col1| col2| col3 | col4
cd | cd |efghijk-lmnoporstuvwxyz | c
but if I remove the option "str x'0D'", in a case of the normal CSV format all row can load currently expect the abnormal row.
load data
CHARACTERSET TH8TISASCII
infile '/data/csv/b.csv' "str x'0D'"
APPEND
PRESERVE BLANKS
into table ITEM2
fields terminated by "," optionally enclosed by '"'
TRAILING NULLCOLS
( col1,
col2,
col3,
col4
)
--Sample CSV file
c, cd, "cdefghijk-lmnop
orstuv
wxyz"
,c
a, ab, "abcdefg", a
b, bc, "bcdefghij", b
d, de, "defghijk",d
--sql loader command
sqlldr USER/PASSWORD readsize=2000000000 bindsize=2000000000 control=file_pointing2.ctl > /data/csv/sqlldr.log
there have 4 records.but the record 1(col3) is not correct
###########################OUT_PUT########################
col1| col2| col3 | col4
c | cd |efghijk-lmnop | c
a | ab |abcdefg | a
b | bc |bcdefghij | b
d | de |defghijk | d
答案 0 :(得分:0)
在第三列附近放置双引号,你需要使用INFILE行上的streaming子句告诉sqlldr回车符是记录字符的结尾,所以在双引号内忽略换行:
9999999999999998
由于我已经在这篇文章中对此进行了解释,请查看更多信息:https://stackoverflow.com/a/37216660/2543416