Solved

Oracle - generating date from (days from Jan 1) in SQL LOADER

Posted on 2013-06-21
7
767 Views
Last Modified: 2013-06-22
We are using SQL Loader to take data from a text file into an Oracle table as we have done many times before.
The date format in the text file is 05150 - two digit year followed by the days since Jan 1 of that year.   We need to convert that into a standard date AND assume that anything < 60 is 1900 + two digit year.

Is there a way to do this in SQL LOADER?

Or, is there a way to call an external DLL or EXE from SQL Loader?
0
Comment
Question by:GNOVAK
  • 3
  • 2
  • 2
7 Comments
 
LVL 76

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 250 total points
ID: 39266636
It can be done in sql loader.

Check out this sample control file:
LOAD DATA
CHARACTERSET WE8ISO8859P1
infile *
INTO TABLE tab1
truncate
(
col1 char(5) "to_date(case when to_number(substr(:col1,1,2)) < 60 then '19' else '20' end || :col1,'YYYYDDD')"
)
begindata
05150

Open in new window

0
 
LVL 32

Expert Comment

by:awking00
ID: 39266639
So you would expect 05150 to be 30-MAY-1905?
0
 
LVL 32

Accepted Solution

by:
awking00 earned 250 total points
ID: 39266681
I suspect you mean the other way around so
05150 would be 30-MAY-2005 and
65150 would be 30-MAY-1965.
If you can live with Oracle's RR designation, which treats years less than 50 as being 1900 and those 50 and above as 2000, then you can just use -
LOAD DATA
INTO tablename
TRUNCATE
(
col1 "to_date(:col1,'RRDDD')"
)
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.

 

Author Comment

by:GNOVAK
ID: 39267213
It would be the opposite of RR I believe.
If it's greater than 50 it would be 1900 and if it's less than 50 it would be 2000
0
 
LVL 76

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 250 total points
ID: 39267298
Using the example I posted, it can be whatever you want.

>>If it's greater than 50 it would be 1900 and if it's less than 50 it would be 2000

I think awking00 mis-typed.

The docs explain how RR works:
http://docs.oracle.com/cd/E11882_01/server.112/e26088/sql_elements004.htm#i116004
0
 

Author Closing Comment

by:GNOVAK
ID: 39268044
Excellent - Thanks!
0
 
LVL 32

Expert Comment

by:awking00
ID: 39268184
Sorry for having mistyped, but you got it figured out :-)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
Subquery in Oracle: Sub queries are one of advance queries in oracle. Types of advance queries: •      Sub Queries •      Hierarchical Queries •      Set Operators Sub queries are know as the query called from another query or another subquery. It can …
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

867 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

21 Experts available now in Live!

Get 1:1 Help Now