Oracle sqlldr 需要 TRAILING NULLCOLS,但为什么呢?
我有一个深奥的 sqlldr 问题困扰着我。我的控制文件看起来像这样:
load data
infile 'txgen.dat'
into table TRANSACTION_NEW
fields terminated by "," optionally enclosed by '"'
TRAILING NULLCOLS
( A,
B,
C,
D,
ID "ID_SEQ.NEXTVAL"
)
数据是这样的:
a,b,c,
a,b,,d
a,b,,
a,b,c,d
如果我不放入尾随 NULLCOLS,我会收到“在逻辑记录结束之前找不到列”错误。但是,尽管有些列为空,但逗号都在那里,所以我不认为 sqlldr 会误解输入文件,并且不会到达从数据库序列生成 ID 的末尾。
此语法以前在没有空列的情况下有效 - 为什么空列会导致 sqlldr 无法到达生成的列?
我已经成功了,我只是想了解为什么!?!
I have an abstruse sqlldr problem that's bothering me. My control file looks something like this:
load data
infile 'txgen.dat'
into table TRANSACTION_NEW
fields terminated by "," optionally enclosed by '"'
TRAILING NULLCOLS
( A,
B,
C,
D,
ID "ID_SEQ.NEXTVAL"
)
Data is something like this:
a,b,c,
a,b,,d
a,b,,
a,b,c,d
If I don't put the TRAILING NULLCOLS in, I get the "column not found before end of logical record" error. But although some of the columns are null, the commas are all there, so I don't see a reason for sqlldr to misinterpret the input file, and not get to the end where it generates the ID from the database sequence.
This syntax has worked before with no null columns - why does a null column cause sqlldr to not reach the generated column?
I've got it working, I just want to understand WHY!?!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您已在控制文件中定义了 5 个字段。您的字段以逗号终止,因此除非指定了 TRAILING NULLCOLS,否则即使您通过 SQL 字符串加载带有序列值的 ID 字段,您也需要在 5 个字段的每条记录中使用 5 个逗号。
RE:OP 的评论
这不是我的简短测试经验。使用以下控制文件:
产生以下输出:
请注意,正确加载的唯一行有 5 个逗号。即使是第三行,除了 ID 之外的所有数据值都存在,数据也不会加载。除非我遗漏了什么...
我正在使用 10gR2。
You have defined 5 fields in your control file. Your fields are terminated by a comma, so you need 5 commas in each record for the 5 fields unless TRAILING NULLCOLS is specified, even though you are loading the ID field with a sequence value via the SQL String.
RE: Comment by OP
That's not my experience with a brief test. With the following control file:
Produced the following output:
Note that the only row that loaded correctly had 5 commas. Even the 3rd row, with all data values present except ID, the data does not load. Unless I'm missing something...
I'm using 10gR2.
这里的问题是,当您想要只使用表达式而不使用数据文件中的任何数据时,您已将 ID 定义为数据文件中的字段。您可以通过将 ID 定义为表达式(或在本例中为序列)来解决此问题
,或者
参见:http://docs.oracle.com/cd/B28359_01/server.111/b28319/ldr_field_list.htm#i1008234 了解所有选项
The problem here is that you have defined ID as a field in your data file when what you want is to just use an expression without any data from the data file. You can fix this by defining ID as an expression (or a sequence in this case)
or
See: http://docs.oracle.com/cd/B28359_01/server.111/b28319/ldr_field_list.htm#i1008234 for all options
输入文件中的最后一列必须包含一些数据(可以是空格或字符,但不能为空)。我猜想,第一条记录在最后一个“,”之后包含空值,除非特别要求使用 TRAILING NULLCOLS 选项识别空值,否则 sqlldr 将无法识别该空值。
或者,如果您不想使用 TRAILING NULLCOLS,则必须在将文件传递给 sqlldr 之前处理这些 NULL。
希望这有帮助
Last column in your input file must have some data in it (be it space or char, but not null). I guess, 1st record contains null after last ',' which sqlldr won't recognize unless specifically asked to recognize nulls using TRAILING NULLCOLS option.
Alternatively, if you don't want to use TRAILING NULLCOLS, you will have to take care of those NULLs before you pass the file to sqlldr.
Hope this helps
尝试在每行中给出 5 个“,”,类似于第 4 行。
Try giving 5 ',' in every line, similar to line number 4.
当 csv 文件中有大量带有空值的额外记录时,我遇到了类似的问题。如果我在记事本中打开 csv 文件,则空行如下所示:
,,,,
,,,,
,,,,
,,,,
如果在 Excel 中打开则看不到这些内容。请检查记事本并删除这些记录
I had similar issue when I had plenty of extra records in csv file with empty values. If I open csv file in notepad then empty lines looks like this:
,,,,
,,,,
,,,,
,,,,
You can not see those if open in Excel. Please check in Notepad and delete those records