如何真正跳过某列的处理?
为了将数据(从 CSV 文件)加载到 Oracle 数据库中,我使用 SQL*Loader。
在接收这些数据的表中,有一个名为 COMMENTS
的 varchar2(500)
列。 由于某些原因,我想忽略 CSV 文件中的此信息。 因此,我编写了这个控制文件:
Options (BindSize=10000000,Readsize=10000000,Rows=5000,Errors=100)
Load Data
Infile 'XXX.txt'
Append into table T_XXX
Fields Terminated By ';'
TRAILING NULLCOLS
(
...
COMMENTS FILLER,
...
)
这段代码似乎工作正常,因为数据库中的 COMMENTS
字段始终设置为 null
。
但是,如果在我的 CSV 文件中,有一条记录,其中相应的 COMMENTS
字段超过 500 个字符的限制,我会从 SQL*Loader 收到错误:
Record 2: Rejected - Error on table T_XXX, column COMMENTS.
Field in data file exceeds maximum length
有没有办法真的 排除对我的 COMMENTS
字段的处理?
In order to load data (from a CSV file) into an Oracle database, I use SQL*Loader.
In the table that receives these data, there is a varchar2(500)
column, called COMMENTS
.
For some reasons, I want to ignore this information from the CSV file.
Thus, I wrote this control file:
Options (BindSize=10000000,Readsize=10000000,Rows=5000,Errors=100)
Load Data
Infile 'XXX.txt'
Append into table T_XXX
Fields Terminated By ';'
TRAILING NULLCOLS
(
...
COMMENTS FILLER,
...
)
This code seems to work correctly, as the COMMENTS
field in database is always set to null
.
However, if in my CSV file I have a record where the corresponding COMMENTS
field exceeds the 500 characters limit, I get an error from SQL*Loader:
Record 2: Rejected - Error on table T_XXX, column COMMENTS.
Field in data file exceeds maximum length
Is there a way to really exclude the processing of my COMMENTS
fields?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我无法重现你的问题。 我正在使用 Oracle 10.2.0.3.0 和 SQL*Loader 10.2.0.1。
这是我的测试用例:
控制文件:
数据文件:
我正在使用命令
sqlldr userid=xxx/yyy@zzz control=test.ctl
并且我得到了所有没有错误的行:您可以尝试另一种方法,我使用以下控制文件得到了相同的期望结果:
更新以下 Romaintaz 的评论:我再次研究它并设法得到与您相同的错误,当列超过 255 个字符。 这是因为 SQL*Loader 的默认数据类型是 char(255)。 如果您有一列包含更多数据,则必须指定长度。 以下控制文件解决了 300 个字符的列的问题:
希望这有帮助,
--
文森特
I can't reproduce your problem. I'm using Oracle 10.2.0.3.0 with SQL*Loader 10.2.0.1.
Here is my test case:
Control file:
data file:
I'm using the command
sqlldr userid=xxx/yyy@zzz control=test.ctl
and I'm getting all the rows without errors:You may try another approach, I'm getting the same desired result with the following control file:
Update following Romaintaz's comment: I looked into it again and managed to get the same error as you when the size of the column exceeded 255 characters. This is because the default datatype of SQL*Loader is char(255). If you have a column with more data you will have to specify the length. The following control file solved the problem for a column with 300 characters:
Hope this Helps,
--
Vincent
只是为了建议一个微小的改进,您可以尝试类似的操作:
现在您将获取所有评论的前 200 个字符(或您在其位置指定的任何数字) - 除非您的某些输入记录的评论字段值超过4000 个字符,其中它们将被加载程序拒绝,并出现前面提到的“超出最大长度”错误。 但假设这种情况很少见或并非如此,所有记录都将加载一些被截断为 200 个字符的评论。
如果您超过
char(4000)
,您将收到 SQL Loader 错误 - 您可以将这头野兽推到多远。Just to suggest a tiny improvement, you might try something like:
Now you'll grab the first 200 characters (or any number you specify in it's place) of all comments - unless some of your input records have values for the comments field that exceed 4000 characters, in which they'll be rejected by loader with the 'exceeds max length' error noted earlier. But assuming that's rare or not the case, all the records will load with some of the comments truncated to 200 chars.
If you go over
char(4000)
you'll get a SQL Loader error - there's a limit to how far you can push the beast.