Solved

Error uploading a file to Oracle with NULL date value

Posted on 2011-09-25
6
435 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
  • 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ODBC Question 3 40
Error when loading the database 16 64
Require data to appear on a single line 2 39
Not able to drop or recreate an Oracle stored procedure 1 26
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
SQL Command Tool comes with APEX under SQL Workshop. It helps us to make changes on the database directly using a graphical user interface. This helps us writing any SQL/ PLSQL queries and execute it on the database and we can create any database ob…
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

815 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now