Oracle External Tables Date Error

5.2k views Asked by At

I get the following errors while loading data into Oracle 11g R2 with EXTERNAL TABLES.

error processing column DATE_M in row 1 for datafile C:\app\S\admin\orcl\dpdump\TABLE_EXT.txt
ORA-01847: day of month must be between 1 and last day of month
error processing column DATE_M in row 2 for datafile C:\app\S\admin\orcl\dpdump\TABLE_EXT.txt
ORA-01843: not a valid month
error processing column DATE_M in row 3 for datafile C:\app\S\admin\orcl\dpdump\TABLE_EXT.txt
ORA-01843: not a valid month
error processing column DATE_M in row 4 for datafile C:\app\S\admin\orcl\dpdump\TABLE_EXT.txt
ORA-01847: day of month must be between 1 and last day of month
error processing column DATE_M in row 5 for datafile C:\app\S\admin\orcl\dpdump\TABLE_EXT.txt
ORA-01843: not a valid month
error processing column DATE_M in row 6 for datafile C:\app\S\admin\orcl\dpdump\TABLE_EXT.txt
ORA-01843: not a valid month
error processing column DATE_M in row 7 for datafile C:\app\S\admin\orcl\dpdump\TABLE_EXT.txt
ORA-01843: not a valid month
error processing column DATE_M in row 8 for datafile C:\app\S\admin\orcl\dpdump\TABLE_EXT.txt
ORA-01843: not a valid month
error processing column DATE_M in row 9 for datafile C:\app\S\admin\orcl\dpdump\TABLE_EXT.txt
ORA-01843: not a valid month
error processing column DATE_M in row 10 for datafile C:\app\S\admin\orcl\dpdump\TABLE_EXT.txt
ORA-01843: not a valid month

External Tables creation:

CREATE TABLE TABLE_EXT
( "COMPANY" VARCHAR2(101), 
"COMPANY_VN" VARCHAR2(15), 
"IL" VARCHAR2(17), 
"TERMINAL" VARCHAR2(8), 
"T_NO" VARCHAR2(15), 
"NAME" VARCHAR2(108), 
"SNAME" VARCHAR2(50), 
"REF_NO" VARCHAR2(23), 
"AMOUNT" NUMBER(15,2), 
"DATE_M" DATE, 
"TIME" VARCHAR2(11), 
"TEL_NO" VARCHAR2(25), 
"ADDRESS" VARCHAR2(50)
) 
ORGANIZATION EXTERNAL (
TYPE ORACLE_LOADER
DEFAULT DIRECTORY data_pump_dir
ACCESS PARAMETERS (
RECORDS DELIMITED BY NEWLINE
FIELDS TERMINATED BY '|'
MISSING FIELD VALUES ARE NULL
(
COMPANY,
COMPANY_VN,
IL,
TERMINAL,
T_NO,
NAME,
SNAME,
REF_NO,
AMOUNT decimal ,
DATE_M CHAR date_format DATE mask "dd.mm.yyyy" ,
TIME,
TEL_NO,
ADDRESS
)
)
LOCATION ('TABLE_EXT.txt')
)

REJECT LIMIT 10

Sample Data:

CITY HOSPITAL|04680072124|CITY|00614860|47746244218|JOHN|WHITE|172871|420,12|21.08.2011|14:26|0806422627784|06
CITY HOSPITAL|04680072124|CITY|00614847|14274017676|BRAD|BROWN|448127|810,00|22.08.2011|11:04|0806427488476|06
CITY HOSPITAL|04680072124|CITY|00614842|16218778886|PETER|BALSON|862626|12,00|24.08.2011|14:16|0806062177008|06
CITY HOSPITAL|04680072124|CITY|00614846|14607666866|GEORGE|LOUIS|688811|40,10|24.08.2011|08:48|0806424172468|06
CITY HOSPITAL|04680072124|CITY|00614846|14607666866|GEORGE|LOUIS|460481|42,64|24.08.2011|08:47|0806424172468|06
CITY HOSPITAL|04680072124|CITY|00614860|18460662462|JR|TEPE|404622|44,16|22.04.2011|20:08|0806446446866|06
CITY HOSPITAL|04680072124|CITY|00614840|47207688618|BARRY|HRAN|402886|42,40|27.08.2011|11:12|0806478768007|06
CITY HOSPITAL|04680072124|CITY|00614847|42161048612|TOM|HIGGS|148640|12,00|06.06.2011|08:18|0806068076700|06
CITY HOSPITAL|04680072124|CITY|00614846|42161048612|TOM|HIGGS|208847|12,00|06.06.2011|08:46|0806068076700|06

.

NLS_DATE_FORMAT : DD/MM/RRRR

NOTE: I tried the following to no avail :

DATE_M DATE "dd.mm.yyyy" ,

DATE_M CHAR date_format DATE mask "DD/MM/RRRR"

1

There are 1 answers

3
DCookie On BEST ANSWER

First, you need to specify your date format mask inside single quotes, not double quotes.

Second, and this is fairly confusing, the format you specify for the "AMOUNT" column is incorrect. When you say the data is "DECIMAL", you are actually specifying a binary format in the input file. You should specify character for the FIELD definitions in the access parameters, and let Oracle convert the field to numeric. I very rarely (if ever) use any format but CHAR to describe the input data to either SQL*Loader or in external tables. That said, however, you're kind of stuck here because I don't think that you can specify the decimal character (',' in your case) in the external table definition. You can only change it via NLS instance parameters.

Here's what i did (note: 10g database) to make your example work:

CREATE TABLE TABLE_EXT ( "COMPANY" VARCHAR2(101)
                      ,  "COMPANY_VN" VARCHAR2(15)
                      ,  "IL" VARCHAR2(17)
                      ,  "TERMINAL" VARCHAR2(8)
                      ,  "T_NO" VARCHAR2(15)
                      ,  "NAME" VARCHAR2(108)
                      ,  "SNAME" VARCHAR2(50)
                      ,  "REF_NO" VARCHAR2(23)
                      ,  "AMOUNT" NUMBER(15,2)
                      ,  "DATE_M" DATE
                      ,  "TIME_M" VARCHAR2(11)
                      ,  "TEL_NO" VARCHAR2(25)
                      ,  "ADDRESS" VARCHAR2(50) )
        ORGANIZATION EXTERNAL 
          ( TYPE ORACLE_LOADER 
            DEFAULT DIRECTORY external_tables 
            ACCESS PARAMETERS 
               ( RECORDS DELIMITED BY NEWLINE 
                  FIELDS TERMINATED BY '|' 
                  MISSING FIELD VALUES ARE NULL 
                 ( COMPANY
                 , COMPANY_VN
                 , IL
                 , TERMINAL
                 , T_NO
                 , NAME
                 , SNAME
                 , REF_NO
                 , AMOUNT 
                 , DATE_M CHAR date_format DATE mask 'dd.mm.yyyy'
                 , TIME_M
                 , TEL_NO
                 , ADDRESS ) ) 
            LOCATION ('TABLE_EXT.txt') )  
            REJECT LIMIT 10 ;

I modified your data slightly to change your decimal character to a '.' in the data:

CITY HOSPITAL|04680072124|CITY|00614860|47746244218|JOHN|WHITE|172871|420.12|21.08.2011|14:26|0806422627784|06
CITY HOSPITAL|04680072124|CITY|00614847|14274017676|BRAD|BROWN|448127|810.00|22.08.2011|11:04|0806427488476|06
CITY HOSPITAL|04680072124|CITY|00614842|16218778886|PETER|BALSON|862626|12.00|24.08.2011|14:16|0806062177008|06
CITY HOSPITAL|04680072124|CITY|00614846|14607666866|GEORGE|LOUIS|688811|40.10|24.08.2011|08:48|0806424172468|06
CITY HOSPITAL|04680072124|CITY|00614846|14607666866|GEORGE|LOUIS|460481|42.64|24.08.2011|08:47|0806424172468|06
CITY HOSPITAL|04680072124|CITY|00614860|18460662462|JR|TEPE|404622|44,16|22.04.2011|20:08|0806446446866|06
CITY HOSPITAL|04680072124|CITY|00614840|47207688618|BARRY|HRAN|402886|42.40|27.08.2011|11:12|0806478768007|06
CITY HOSPITAL|04680072124|CITY|00614847|42161048612|TOM|HIGGS|148640|12.00|06.06.2011|08:18|0806068076700|06
CITY HOSPITAL|04680072124|CITY|00614846|42161048612|TOM|HIGGS|208847|12.00|06.06.2011|08:46|0806068076700|06

This worked for me.

Bottom line, I think you'll need to (1)modify your data, (2) modify your instance NLS parameters to change the decimal character or (3) load your data as character and use the TO_NUMBER function in a view on top of the external table.