Reputation: 873
SQL> desc FLIGHTS;
Name Null? Type
----------------------------------------- -------- ----------------------------
FLNO NUMBER(38)
FROM VARCHAR2(64)
TO VARCHAR2(64)
DISTANCE NUMBER(38)
DEPARTS DATE
ARRIVES DATE
PRICE FLOAT(63)
data file:
99,Los Angeles,Washington D.C.,2308,2005/04/12 09:30,2005/04/12 21:40,235.98
13,Los Angeles,Chicago,1749,2005/04/12 08:45,2005/04/12 20:45,220.98
346,Los Angeles,Dallas,1251,2005/04/12 11:50,2005/04/12 19:05,225.43
387,Los Angeles,Boston,2606,2005/04/12 07:03,2005/04/12 17:03,261.56
and sqlldr control file:
LOAD DATA INFILE 'flights.txt'
INTO TABLE Flights
FIELDS TERMINATED BY ","
( FLNO
, FROM
, TO
, DISTANCE
, DEPARTS
, ARRIVES
, PRICE)
An exerpt from the error log:
Table FLIGHTS, loaded from every logical record.
Insert option in effect for this table: INSERT
Column Name Position Len Term Encl Datatype
------------------------------ ---------- ----- ---- ---- ---------------------
FLNO FIRST * , CHARACTER
FROM NEXT * , CHARACTER
TO NEXT * , CHARACTER
DISTANCE NEXT * , CHARACTER
DEPARTS NEXT * , CHARACTER
ARRIVES NEXT * , CHARACTER
PRICE NEXT * , CHARACTER
Record 1: Rejected - Error on table FLIGHTS, column FROM.
ORA-01747: invalid user.table.column, table.column, or column specification
I am not sure what is wrong with my SQL, but I'm assuming it is because of the FROM
entry?
Upvotes: 0
Views: 2833
Reputation: 52843
Firstly, calling columns from
and to
is a bad idea, they're key-words. Something like origin
and destination
might be better...
Secondly, float
, this really isn't needed. The chances of you needing a price to 63 decimal places is remote. Something like number(18,2)
should be more than sufficient (ridiculous in fact), but if you want the absolute maximum use number(38,2)
.
My last pre-answer point is your datafile. If at all possible get your supplier to change this. A comma delimited file is just asking for trouble... there are far too many ways for a comma to be in the data. If you can have it |
or ¬
delimited it's better as they're hardly ever used in text.
Depending on your NLS_PARAMETERS
, there's no guarantee that the date in the file will be altered into the date you need in your table. It's best to explicitly specify this on entry into the database like this:
LOAD DATA
INFILE 'flights.txt'
INTO TABLE Flights
FIELDS TERMINATED BY ","
( FLNO
, FROM
, TO
, DISTANCE
, DEPARTS "to_date(:departs,'yyyy/mm/dd hh24:mi')"
, ARRIVES "to_date(:arrives,'yyyy/mm/dd hh24:mi')"
, PRICE DECIMAL EXTERNAL
)
Notice that I've also changed PRICE
into a decimal, if you look at your log file, everything is supposedly a character, which means you're doing an implicit conversion, which may not be guaranteed.
Why you got your specific error message? I don't actually know. I also suspect it's because you've got a column called FROM
. According to the control file documentation there's no SQL*Loader keyword from
, so I can only posit that it's some problem with SQL*Loader's communication with Oracle.
Here's another good resource on syntax.
Upvotes: 2