外部表-“文件末尾的部分记录”使用 FIXED 时出错
在外部表中使用 FIXED 参数时,我收到“文件末尾的部分记录”错误。
我正在使用 SQL Developer、Oracle 11g XE。
-------
foo.dat - Field lengths: fname=7;lname=8;year=4
-------
Alvin Tolliver1976
KennethBaer 1963
Mary Dube 1973
以下是该表的 DDL:
CREATE TABLE emp_load (
first_name CHAR(7)
, last_name CHAR(8)
, year_of_birth CHAR(4)
)
ORGANIZATION EXTERNAL (
TYPE ORACLE_LOADER
DEFAULT DIRECTORY ext_tab_dir
ACCESS PARAMETERS (
RECORDS FIXED 20 FIELDS (
first_name CHAR(7)
, last_name CHAR(8)
, year_of_birth CHAR(4)
)
)
LOCATION ('foo.dat'));
正在创建表 emp_load,但 select 语句失败并显示以下错误消息。 执行 select * from emp_load
时出现错误消息:
ORA-29913: error in executing ODCIEXTTABLEFETCH callout
ORA-29400: data cartridge error
KUP-04018: <b>partial record at end of file C:\oracle\foo.dat</b>
29913. 00000 - "error in executing %s callout"
*Cause: The execution of the specified callout caused an error.
*Action: Examine the error messages take appropriate action.
唯一有效的一次是当我制作 foo.dat 1 行(如下所示)并将 FIXED 长度更改为 19 时 -
Alvin Tolliver1976KennethBaer 1963Mary Dube 1973
这似乎表明我是对换行符做了一些错误的事情,但我不知道是什么。
任何帮助将不胜感激。提前致谢!
I am getting a "partial record at end of file" error when using FIXED parameter with External Tables.
I am using SQL Developer, Oracle 11g XE.
-------
foo.dat - Field lengths: fname=7;lname=8;year=4
-------
Alvin Tolliver1976
KennethBaer 1963
Mary Dube 1973
Here is the DDL for the table:
CREATE TABLE emp_load (
first_name CHAR(7)
, last_name CHAR(8)
, year_of_birth CHAR(4)
)
ORGANIZATION EXTERNAL (
TYPE ORACLE_LOADER
DEFAULT DIRECTORY ext_tab_dir
ACCESS PARAMETERS (
RECORDS FIXED 20 FIELDS (
first_name CHAR(7)
, last_name CHAR(8)
, year_of_birth CHAR(4)
)
)
LOCATION ('foo.dat'));
The table emp_load is getting created, but select statement fails with below error message.
Error message when doing select * from emp_load
:
ORA-29913: error in executing ODCIEXTTABLEFETCH callout
ORA-29400: data cartridge error
KUP-04018: <b>partial record at end of file C:\oracle\foo.dat</b>
29913. 00000 - "error in executing %s callout"
*Cause: The execution of the specified callout caused an error.
*Action: Examine the error messages take appropriate action.
The only time it worked is when I made foo.dat 1 line (as below) and I changed the FIXED length to 19-
Alvin Tolliver1976KennethBaer 1963Mary Dube 1973
This seems to indicate that I am doing something wrong with regards to newline characters, but I cannot figure out what.
Any help would be appreciated. Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
多行数据文件中最后一行之后缺少换行符。即你的最后一行长度是 19 字节而不是 20 字节。您可以检查数据文件的大小 - 它应该是 3 * 20 = 60 字节。
当您更改数据文件以将所有数据放在一行中并使用
RECORDS FIXED 19
时,一切都会再次正常,因为现在不需要换行符。You are missing a newline character after the last line in your multi-line data file. I.e your last line length is 19 bytes not 20 bytes. You can check the size of your data file - it should be 3 * 20 = 60 bytes.
When you change the data file to have all data in a single line and use
RECORDS FIXED 19
everything is again well because now newline is not expected.我找到了答案。
文档说 FIXED 假定末尾有一个换行符。
在 Windows 中,换行符 (\r\n) 占用 2 个字节。
因此,在 Windows 中,传递给 FIXED 的长度应该 = 字段总长度 + 2
在 Unix 中,它应该 = 字段总长度 + 1
我在 Windows Vista 计算机上安装了 Oracle 11g。 因此 21 是总长度,而不是 20。
文档中的示例可能适用于 Unix,它使用 1 个字节作为换行符 (\n)
因此,如果在 Windows 上安装了 Oracle 11g,则这是正确的代码-
感谢 ypercube 提供替代解决方案。我已经赞成你的建议了。
(ypercube 建议使用 DELIMITED BY NEWLINE 提供了一种替代方案,实际上是一个更简单的解决方案。但我想发布上述内容,因为我认为这对于尝试使用 Oracle 文档中的 FIXED 示例的人来说会很有用。)
I found the answer..
The documentation says that FIXED assumes a newline character at the end.
In Windows, newline (\r\n) takes up 2 bytes.
So, in Windows, the length to be passed to FIXED should be = total length of fields + 2
In Unix, it should be = total length of fields + 1
I have installed the Oracle 11g on my Windows Vista machine. So 21 is the total length instead of 20.
The example in the documentation was probably for Unix which uses 1 byte for newline (\n)
So, this is the correct code if Oracle 11g is installed on Windows -
Thanks ypercube for the alternative solution. I have upvoted your suggestion.
(ypercube's suggestion to use DELIMITED BY NEWLINE provided an alternative, actually an easier solution. But I wanted to post the above since I think it will be useful to someone trying to use the example from the Oracle documentation for FIXED.)