convert MM/DD/YYYY IN TO DD-MON-YYYY

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

praburaj
Premium Member
Premium Member
Posts: 133
Joined: Thu Jun 30, 2005 1:26 am
Location: philippines

convert MM/DD/YYYY IN TO DD-MON-YYYY

Post by praburaj »

Hai,

I want to convert date like this MM/DD/YYYY IN TO DD-MON-YYYY.

My Source is Oci Stage and My Target also Oci Stage. My Date Column

Name is Earned Date in source (VARCHAR 38) NULL - YES, In My Target

Column Name is Agg_Earned_date(DATE ) NULL -YES.

I have written query in transformer like this

Oconv(Iconv(LNK_STAGE_PERIPHERALUS_SURVEY_JRNL_REV_EXT.EARNED_DT,"DMDY

[2,2,4]":@VM:"MCN"),"D-DMY[2,A3,4]")

when i run the job, i got the result in sequential file(31-DEC-2006). But

when i check in to the Oci stage, i did not get the result. I don't know

where is the problem. Even i have tried to change the Target Column

Data type like Varchar, TimeStamp like this. But whenever i have view

the data, the corresponding column(AGG_EARNED_DATE), it didn't show

any data.

That means that column having no data. I don't know where is the

problem. Would you please help me? How can i solve the problem. If

any problem in my query, please send me the correct query.

with regards,

prabu
kris007
Charter Member
Charter Member
Posts: 1102
Joined: Tue Jan 24, 2006 5:38 pm
Location: Riverside, RI

Re: convert MM/DD/YYYY IN TO DD-MON-YYYY

Post by kris007 »

praburaj wrote: Even i have tried to change the Target Column
Data type like Varchar, TimeStamp like this.
Where did you try changing the datatype? In the table or within the OCI stage? Also, Oracle accepts date in the format YYYY-MM-DD unless you have set your default value otherwise. Try changing the datatype in the table to varchar and see if that works.
Kris

Where's the "Any" key?-Homer Simpson
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

The OCI stages require the 'Timestamp' datatype to be in the following format:

YYYY-MM-DD HH24:MI:SS

As can be seen by the sql the stage generates. If you don't need to time portion that a DATE field can carry, then just tack on a zero time to the end of your date: " 00:00:00".
-craig

"You can never have too many knives" -- Logan Nine Fingers
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Is your target a Date field or Timestamp field ?
If date the do this

Code: Select all

OCONV(ICONV(in.date, "D/MDY[2,2,4]"), "D-YMD[4,2,2]")
This will convert your outpu to YYYY-MM-DD which oracle accepts.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

People, Oracle will accept any date format - as long as the proper TO_DATE mask goes along with it. And unless you are a fan of user-defined sql places where it ain't needed, I'd suggest you stick with the format that matches the sql the stage will auto-generate. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
praburaj
Premium Member
Premium Member
Posts: 133
Joined: Thu Jun 30, 2005 1:26 am
Location: philippines

Post by praburaj »

Guru, Is your code convert the date format MM/DD/YYY(12/03/2006( TO

DD-MON-YYYY(03-DEC-2006) like this? pls clear my doubt..

And I have one more doubt. I need date format like this 03-DEC-2006

in OCI stage. Is it possible to change the date format inside the OCI

STAGE like this ( To_date(Mycolumn DD-MON-YYYY). I am going to give

this condition in USER DEFINED SQL. Because,Whenever i am trying to

view the data, i am getting the Null Value for the correponding column.

Plz, clear My doubt. If it is wrong, how can i do that?

Can I use the same query in transformer:


Oconv(Iconv

(LNK_STAGE_PERIPHERALUS_SURVEY_JRNL_REV_EXT.EARNED_DT,"DMDY
[2,2,4]":@VM:"MCN"),"D-DMY[2,A3,4]") with user_defined Sql condition.


Plz help me :roll:
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

praburaj wrote:I need date format like this 03-DEC-2006 in OCI stage. Is it possible to change the date format inside the OCI STAGE like this ( To_date(Mycolumn DD-MON-YYYY). I am going to give this condition in USER DEFINED SQL.
No, you don't "need" the date in that format.

No, that's not what the TO_DATE needs to look like.

No, you don't "need" user defined sql for this - in fact you do yourself a great disservice by using it when there's absolutely no need to do so.

:idea: If you consistently treat your Oracle dates as Timestamps in DataStage and build yourself some routines to standardize date handling, then you will never have another issue handling Oracle dates again. It's really not that mysterious, folks.

Read the OCI stage docs or simply examine the sql the stage generates for a Timestamp datatype. As I've already meantioned, it is expecting you to supply data in the following format:

YYYY-MM-DD HH24:MI:SS

A standard ISO timestamp. Convert your date in the Transformer using the following Conv pair, first taking it to Internal format and then bringing it back out in External format in the format desired:

Code: Select all

OConv(IConv(Link.Column, "D"),"D-YMD[4,2,2]"):" 00:00:00"
These kinds of OConv/IConv pairs are standard fare when handling any date, not just 'for Oracle' so suggest you get comfortable with them and make them part of your daily arsenal of weapons when attacking dates.

In my opinion, it's best to always treat an Oracle DATE using a full Timestamp value - this way you have explicit control over the 'time' portion that each date optionally carries in Oracle. If you want 'no time' then ensure that by passing a zero time as shown above.

The resulting Timestamp value can be sent to the OCI stage and with Generated SQL will load just fine.

ps. What are you using to post these messages? Everything is double-spaced with hard returns at the end of every line. There's no need for that and makes reading and responding to your posts a pain. :evil:
-craig

"You can never have too many knives" -- Logan Nine Fingers
praburaj
Premium Member
Premium Member
Posts: 133
Joined: Thu Jun 30, 2005 1:26 am
Location: philippines

Post by praburaj »

I have tried Even this code also.
OConv(IConv(Link.Column, "D"),"D-YMD[4,2,2]"):" 00:00:00" . Still I am getting Null value for that corresponding column. My target is OCI Stage.
Column Name : Earned_date Datatype: TimeStamp Length :20.


Source Date Format : 21/31/2006 data type : varchar

Output Need : 31-DEC-2006 data type : date


I have tried as far as possible. But still i am getting null value.

How can i solve that. Plz help me. :roll:
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

How can you solve it? By telling us whatever it is that you are not telling us that is causing this to fail. :evil:

There is nothing wrong with the derivation posted and it does work when used properly as I've done this very thing in thousands of jobs over the years. You need to triple-check everything you are doing, make no assumptions about what you've done or must have done correctly - check everything. As I noted, you'll also need to let the stage generate the sql for you, you're not doing any of that silly user-defined crap, are you? Are you getting any warnings in the job's log when it runs and gives you this 'null value'? There's definitely some key piece of information you're withholding. You need to figure it out, we can't from the wrong side of the glass. :roll:

So, the big summary - the rest is up to you:

* Oracle DATE field
* OCI target stage
* Timestamp datatype in job
* Timestamp size: 38 Display size: 20
* Correct source field mapped to correct target field
* Derivation: OConv(IConv(Link.Column, "D"),"D-YMD[4,2,2]"):" 00:00:00"
* SQL generated by the stage, not user-defined

That is all you need. If this still doesn't work, make sure you come back with a warning or an error or some other reason why it doesn't work - otherwise all anyone can do is repeat everything that's already been said in this thread and ask you to check what you are doing again.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

All of the derivations will generate NULL if there is NULL in the source.

You need to do some detective work - perhaps using the debugger, perhaps using stage tracing - to determine in which line these NULL values are occurring.

I would also ask you to demonstrate that what you are getting really is NULL, not zero-length string (""). These are not the same thing.

Start by taking the OCI target stage out of the design - use a Sequential File stage, and determine those rows in which you do not get a timestamp in the column in question.
Last edited by ray.wurlod on Mon Dec 25, 2006 9:05 pm, edited 1 time in total.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

I don't know about you, Ray, but I made the assumption that when someone complains about their end result being null that they know it shouldn't be. Call me crazy or a heretic, but... still, point taken and (hopefully) duly noted. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Wow, lots of fun chit chat huh. I see craig had fun over the holidays :wink:
Praburaj, i think Craig cleared out your question that was referred to me. There isnt really much we can do from this side of the glass as Craig already pointed out to you. Follow the second last entry of Craig and post the results.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
praburaj
Premium Member
Premium Member
Posts: 133
Joined: Thu Jun 30, 2005 1:26 am
Location: philippines

Post by praburaj »

Hai Chulett,

At last I got data for that column. But Still i have problem. I have applied ur code. But I did not get the correct result. Same Source data has inserted(22/12/2006) in to the target stage like this (22/12/2006).

My table Both Source and Target no primary key. How can i solve that? :(
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

So you got your date issue resolved. Is that what you are saying???
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Add a primary key to both tables. [/jk]

What are you trying to solve now? Are you saying it is working? According to Sunshine you're still generating warnings...
-craig

"You can never have too many knives" -- Logan Nine Fingers
Post Reply