Solved

Error uploading a file to Oracle with NULL date value

Posted on 2011-09-25
6
432 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
Via a live example, show how to take different types of Oracle backups using RMAN.

759 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

19 Experts available now in Live!

Get 1:1 Help Now