Solved

Error uploading a file to Oracle with NULL date value

Posted on 2011-09-25
6
442 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
Do you have a plan for Continuity?

It's inevitable. People leave organizations creating a gap in your service. That's where Percona comes in.

See how Pepper.com relies on Percona to:
-Manage their database
-Guarantee data safety and protection
-Provide database expertise that is available for any situation

 
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Recently I was talking with Tim Sharp, one of my colleagues from our Technical Account Manager team about MongoDB’s scalability. While doing some quick training with some of the Percona team, Tim brought something to my attention...
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.

691 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