problem with dates loading in Oracle

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

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

Post by chulett »

Your time transformation isn't quite right. You need to tell it that it is coming in in 12 hour format but you want it out in 24 hour format. Try this:

Code: Select all

oconv(iconv(stgvar2,"MTHS"),"MTS") 
-craig

"You can never have too many knives" -- Logan Nine Fingers
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

Craig, your points are strong and valid.
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
paddu
Premium Member
Premium Member
Posts: 232
Joined: Tue Feb 22, 2005 11:14 am
Location: California

Post by paddu »

OCONV(ICONV(stgvar1,"D/MDY[2,2,4]"),"D-YMD[4,2,2]") : " " : oconv(iconv(stgvar2,"MTHS"),"MTS")


results in 2/24/2007 only .

is something wrong with my right function where i pick 10 characters 1:18:19 PM?

Craig- i even loaded to Flatfile and the result of the file is 2007-02-24

Appreciate your patience and great help

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

Post by chulett »

What happens when it's 10 PM? Let's say the time is 10:18:19 PM - what happens when you take the right 10 characters? Same with the dates - months and days can be a single digit or two digits in your format.

Better to use the field command to split it, not a fixed substring. Tell it that the field is 'space delimited' and you want the 'fields' on either side of that first space:

Code: Select all

stgvar1: Field(src_out_C_CUST_MTCH.CREATE_DATE," ",1,1)
stgvar2: Field(src_out_C_CUST_MTCH.CREATE_DATE," ",2,99)
stgvar1 gets the first field while stgvar2 gets 'all' of the fields after the first one. Give that a shot.

ps. I'd strongly suggest you try to use more descriptive stage variable names, that will help to make your derivations more 'self documenting'. stgvar1 and stgvar2 mean nothing but svTimestampDate and svTimestampTime (as an example) do. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
paddu
Premium Member
Premium Member
Posts: 232
Joined: Tue Feb 22, 2005 11:14 am
Location: California

Post by paddu »

Craig- i will surely make all the cosmetic changes once the job works fine :)
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Ok, fair enough. Keep in mind the fact that the job may no longer function after you make these 'cosmetic' changes. :P

Did the field function suggestion help?
-craig

"You can never have too many knives" -- Logan Nine Fingers
paddu
Premium Member
Premium Member
Posts: 232
Joined: Tue Feb 22, 2005 11:14 am
Location: California

Post by paddu »

Craig

I tried using the field function as you suggested but the result is only date 2007-02-24 in the flatfile.

As we needed the file to be loaded in the oracle table yesterday , i used sysdate to populate into Create_date field . This is a one time job as per requirement and Create_date field is not a critical field for the business.

Business may not be interested to know why the actual Create_date values coming from Flatfile were not loaded ( as it is a Batch process timestamp) but i am very much interested to know how to solve this issue.


Any suggestions appreciated.

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

Post by chulett »

Huh... there's no reason that I can see here why the techniques posted wouldn't work as this is pretty standard timestamp work. :?

Can you repost (since it has been through some modifications) exactly how you are doing this now? Cut and paste from the job things like the stage variable derivations, the derivation for the flat file field you are writing to, how that field is defined and some samples of input and output data?

I'd also suggest you write the two stage variables to separate fields in the flat file as well as the 'concatenated' value for diagnostic purposes.
-craig

"You can never have too many knives" -- Logan Nine Fingers
paddu
Premium Member
Premium Member
Posts: 232
Joined: Tue Feb 22, 2005 11:14 am
Location: California

Post by paddu »

Sample input Data Flatfile :

2/24/2007 1:18:19 PM Infact this the only date for all the 1050356 records from the source

stage variables used to split the date & time

svTimestampDate :Field(src_out_C_CUST_MTCH.CREATE_DATE," ",1,1)
svTimestampTime:Field(src_out_C_CUST_MTCH.CREATE_DATE," ",2,99)

Conversion used

Create_date(field)- OCONV(ICONV(svTimestampDate,"D/MDY[2,2,4]"),"D-YMD[4,2,2]") : " " : oconv(iconv(svTimestampTime,"MTHS"),"MTS")

Result of

Create_date ---- 2007-02-24
svTimestampDate--- 2/24/2007
svTimestampTime--- 1:18:19 PM


Please let me know if you need more.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

All that's working. But when you create a timestamp, you don't want the AM/PM designator. Your derivation for Create_Date is correct, unless there's a newline in it. It must be on a single line. For example (for an ISO 8601 timestamp):

Code: Select all

Oconv(Iconv(svTimestampDate, "DMDY"), "D-YMD[4,2,2]") : " " : Oconv(Iconv(svTimestampTime, "MTHS"), "MTS")
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 »

Which is (allegedly) exactly what he is doing. :?

You should also create two more stage variables and add them to the diagnostic file. We know you are parsing the input string correctly but nothing else for certain. Do the conversions in the stage variables and just the concatenation in the final derivation.

stage variables used to split the date & time

svTimestampDate :Field(src_out_C_CUST_MTCH.CREATE_DATE," ",1,1)
svTimestampTime:Field(src_out_C_CUST_MTCH.CREATE_DATE," ",2,99)
svDate: OCONV(ICONV(svTimestampDate,"D/MDY[2,2,4]"),"D-YMD[4,2,2]")
svTime: OCONV(ICONV(svTimestampTime,"MTHS"),"MTS")

Conversion used

Create_date(field): svDate : " " : svTime


Then dump all four stage variables and post them here.
-craig

"You can never have too many knives" -- Logan Nine Fingers
paddu
Premium Member
Premium Member
Posts: 232
Joined: Tue Feb 22, 2005 11:14 am
Location: California

Post by paddu »

svTimestampDate-Field(src_out_C_CUST_MTCH.CREATE_DATE," ",1,1)
svTimestampTime-Field(src_out_C_CUST_MTCH.CREATE_DATE," ",2,99)
svDate- OCONV(ICONV(svTimestampDate,"D/MDY[2,2,4]"),"D-YMD[4,2,2]")
svTime-oconv(iconv(svTimestampTime,"MTHS"),"MTS")


results of four stage variables

Create_Date - 2007-02-24
svTimestampDate-2/24/2007
svTimestampTime-1:18:19 PM
svDate-2007-02-24
svTime-Blank
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Well... there ya go. Your time transformation is failing for some reason. Now just need to puzzle out the why of it...
-craig

"You can never have too many knives" -- Logan Nine Fingers
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Ok, that wasn't so hard to figure out. Built a small testbed routine to check the conversions and found that it doesn't like the space in the time before the AM/PM part. Silly Wabbit.

Try this:

svTimestampTime: Convert(" ","",Field(src_out_C_CUST_MTCH.CREATE_DATE," ",2,99))
-craig

"You can never have too many knives" -- Logan Nine Fingers
paddu
Premium Member
Premium Member
Posts: 232
Joined: Tue Feb 22, 2005 11:14 am
Location: California

Post by paddu »

Craig-Well... there ya go. Your time transformation is failing for some reason. Now just need to puzzle out the why of it...

yes that's why i asked ,was something wrong with my right function (time transformation)???in my earlier post.

I used the stage variable you suggested and
finally the results are

Create Date: 2007-02-24 13:18:19
svTimestampDate-2/24/2007
svTimestampTime-1:18:19 PM
svDate-2007-02-24
svTime-13:18:19

Craig- Thanks a lot for your patience and valuable information

Thanks everyone
Paddu
Post Reply