Solved

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

Posted on 2013-06-21
7
771 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

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.

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…
Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…

813 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

18 Experts available now in Live!

Get 1:1 Help Now