Solved

Error uploading a file to Oracle with NULL date value

Posted on 2011-09-25
6
439 Views
Last Modified: 2012-05-12
How can I upload to Oracle (11gR2) database table via sqlloader when date field has a null value.

I have attached the Control file , sample records and the error log.

All lines are getting rejected. As all lines have at least one empty Date value for the DATE fields f2, f4, f5, f6, f7 and f8.

The sqlload works fine when there are date values.
Control file:
OPTIONS (SKIP = 2, ERRORS = 1000, ROWS = 66796)
load data
 infile '/var/www//myfile.txt'
 TRUNCATE
 INTO TABLE mytab
 fields terminated by ','
 TRAILING NULLCOLS
(
f1,
f2 DATE 'mm/dd/yyyy',
f3,
f4 DATE 'mm/dd/yyyy',
f5 DATE 'mm/dd/yyyy',
f6 DATE 'mm/dd/yyyy',
f7 DATE 'mm/dd/yyyy',
f8 DATE 'mm/dd/yyyy'
)

SAMPLE lines of the data file myfile.txt:

204,                                    ,        ,      ,      ,      ,      ,
205,                                    ,        ,      ,      ,      ,      ,
206,                                    ,        ,      ,      ,      ,      ,
207,                                    ,        ,      ,      ,      ,      ,


SqlLoaderLog file:
Record 1: Rejected - Error on table mytab, column f2.
ORA-01843: not a valid month

Open in new window

0
Comment
Question by:toooki
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 23

Expert Comment

by:OP_Zaharin
ID: 36597288
- you can use nullif. following example is from memory:

f2 DATE 'mm/dd/yyyy' nullif (f2=BLANKS),

or

f2 DATE "mm/dd/yyyy" nullif f2=BLANKS,
0
 
LVL 23

Expert Comment

by:OP_Zaharin
ID: 36597323
hi tooki,
- i've tested and following is the working syntax. you need to do the same with the other date column:

f2 DATE "mm/dd/yyyy" nullif (f2=BLANKS),
0
 

Author Comment

by:toooki
ID: 36600389
Many thanks OP_Zaharin .
But it is not working. I get the same error.
Record 1: Rejected - Error on table mytab, column f2.
ORA-01843: not a valid month

No record gets loaded. This is probably because of space characters instead of BLANKS for that line in the data file.. Trying to troubleshoot..
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 23

Accepted Solution

by:
OP_Zaharin earned 475 total points
ID: 36668541
- i've tested the control file with sample of date with spaces (i manually press spacebar for the space), it seems able to load without error. can u try use trim() function on the date column.

f2 DATE "mm/dd/yyyy" nullif (f2=BLANKS) "TRIM(:f2)",

or

f2 DATE "mm/dd/yyyy" nullif f2=BLANKS "TRIM(:f2)",
0
 

Author Comment

by:toooki
ID: 36898423
Many thanks.

I tried but that did not work. Maybe somewhere some data is not in correct format in th ehuge table.
So I gave up and tried this way. I made the field varchar2. And it worked with the control file.

Then I created another table to read the varchar2 and converted to DATE. It is less difficult to convert when inside the oracle table.

Thanks!
0
 
LVL 23

Expert Comment

by:OP_Zaharin
ID: 36898476
- no problem toooki. yes i agree that is another way of handling the data when using sqlloader. there will be times i create a temp table, using sqlloader to load the data from text file into the temp table then do data cleansing in the temp table form rather that managing it thru sqlloader control file.  after the data is confirmed then i moved the data into the actual table. it might looks too many steps but the important is the data integrity is handled properly.

OP
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question