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, bu开发者_如何学Pythont I cannot figure out what.
Any help would be appreciated. Thanks in advance!
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.
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 -
CREATE TABLE emp_load (first_name CHAR(15), last_name CHAR(20), year_of_birth CHAR(4)) ORGANIZATION EXTERNAL (TYPE ORACLE_LOADER DEFAULT DIRECTORY filesdir ACCESS PARAMETERS (RECORDS FIXED 21 FIELDS (first_name CHAR(7), last_name CHAR(8), year_of_birth CHAR(4))) LOCATION ('info1.dat'));
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.)
精彩评论