Oracle datetime field conversion

A forum for discussing DataStage<sup>®</sup> basics. If you're not sure where your question goes, start here.

Moderators: chulett, rschirm, roy

Post Reply
Aggie99
Participant
Posts: 54
Joined: Thu Sep 04, 2008 6:54 pm

Oracle datetime field conversion

Post by Aggie99 »

I have a datetime field that looks like
"12-JUL-09 07.02.00.000000 AM" and store in a csv file (that is the source file).

My target is an Oracle table. the above field is defined as "timestamp" in the Oracle table.

I have problem loading the source field into the target table. What do I need to do so I can load this datetime field into Oracle?

Please help.
dxk9
Participant
Posts: 105
Joined: Wed Aug 19, 2009 12:46 am
Location: Chennai, Tamil Nadu

Post by dxk9 »

Hi,
If all the data in that field is of "12-JUL-09 07.02.00.000000 AM" format (I mean fixed length), then you can convert the data to "12-JUL-2009 07:02:00 AM" in the transformer using string functions and the use string to timestamp function.

Regards,
Divya
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

You need to transform whatever format is coming in into the format expected by the default Oracle timestamp picture (or supply a non-default picture).
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Aggie99
Participant
Posts: 54
Joined: Thu Sep 04, 2008 6:54 pm

Post by Aggie99 »

dxk, can you give me an example of what you mean. yes, all the records have are fixed lengt.


ray, the format is already Oracle native format. I can use sqlldr to load the file, but I can't load using datastage Oracle Enterprise Stage.

Stages that I used:

Sequential file (read csv in) -> Transformer -> Oracle Enterprise Stage (load to target table). What should I specify as the datetime format, I am a bit lost in the translation.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

What is your target field - a DATE or a TIMESTAMP? If the latter, what is the precision of the timestamp?

And there's no such thing as "Oracle native format" unless you're trying to say it matches the current NLS_DATE_FORMAT or NLS_TIMESTAMP_FORMAT for the target database.
-craig

"You can never have too many knives" -- Logan Nine Fingers
dxk9
Participant
Posts: 105
Joined: Wed Aug 19, 2009 12:46 am
Location: Chennai, Tamil Nadu

Post by dxk9 »

Hi,
dxk9 wrote:Hi,
If all the data in that field is of "12-JUL-09 07.02.00.000000 AM" format (I mean fixed length), then you can convert the data to "12-JUL-2009 07:02:00 AM" in the transformer using string functions and the use string to timestamp function.

Say for eg: you have date as "12-JUL-09 07.02.00.000000 AM", you can import the data as string(varchar) prior to join, then you can do the join. In this case, if this is not matching with the left side table, this field will return a NULL value. Then you can use a transformer post the join and convert the field to timestamp using stringtotimestamp() function.

It will be something like:

If isnull(<input_date_field>) then setnull() else if len(trim<input_date_field>)=0 then setnull() else stringtotimestamp(<input>,<format>)

Remember that before using the above conversion, you should first convert the "12-JUL-09 07.02.00.000000 AM" to "12-JUL-09 07:02:00 AM" using string functions like LEFT,CONCATENATE (:),RIGHT in transformer.

Regards,
Divya
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Where did 'join' come from? This is about 'load' not 'join'. :?
-craig

"You can never have too many knives" -- Logan Nine Fingers
priyadarshikunal
Premium Member
Premium Member
Posts: 1735
Joined: Thu Mar 01, 2007 5:44 am
Location: Troy, MI

Post by priyadarshikunal »

why you need to remove microsecond part only to load that value?

assuming precision as 6

you just need to use ".6" after "ss" in date mask in transformer, mention scale as 6 in column property thats all.

in custom sql you need to use to_timestamp(input,format)

in format mention ".ff6" after ss in the date format.
Priyadarshi Kunal

Genius may have its limitations, but stupidity is not thus handicapped. :wink:
Post Reply