DS equivalent of DECODE function of 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

Post Reply
rxs0005
Participant
Posts: 18
Joined: Fri Oct 07, 2005 4:29 am

DS equivalent of DECODE function of Oracle

Post by rxs0005 »

hi all,

I need to do an transformation based on DECODE logic i use in oracle

in the TRANSFORMER which fucntion / routine i use

thanks

eg:

update table
set col_X = decode(col_x, null, ABC, 0, ABC, col_X )
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

You can always use the CONVERT statement , which is rather cool. It takes a string of characters and changes the each value to a correlated value in another string.

Example:

Code: Select all

CONVERT "ABC" TO "123" IN yourstring
This would change all occurrences of "A" to a "1", "B" to a "2", and "C" to a "3".

So,

Code: Select all

CONVERT "ABC" TO "123" IN "CxBxA"
produces

Code: Select all

3x2x1
Now, if you have wordsinstead of single characters, you're going to have to write your own decode function. There is no word-level matching. You'll have to pass a delimited string of search values and their replacement values to the function. You can use smart array logic to LOCATE (look it up) the search value and then return the correlated result.
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
rxs0005
Participant
Posts: 18
Joined: Fri Oct 07, 2005 4:29 am

Post by rxs0005 »

Kc

thanks i had a Q regarding CONVERT instead of hard coded values i can substitute a column name form the same table right for eg:

update table
set col_X = decode(col_x, null, col_Y , 0, col_Y, col_X )

thanks

R
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

What do you mean, column name? Are you talking about during the actual SQL execution? It's too late. If you need the before-image of a row you need to update, use a reference lookup of some fashion and make the new data and the current data available in the transformer in order to do the logic you desire.
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
kduke
Charter Member
Charter Member
Posts: 5227
Joined: Thu May 29, 2003 9:47 am
Location: Dallas, TX
Contact:

Post by kduke »

Why not if then else.
Mamu Kim
Post Reply