Column with not fixed number of delimited values

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
Sham9
Participant
Posts: 7
Joined: Wed Nov 09, 2016 11:34 pm

Column with not fixed number of delimited values

Post by Sham9 »

Hello,

I have a requirement where my source is oracle table and one of the column containes value separated by commas. I want to create individual record for these values. For example

Input
------

Colum1| Column 2
123456| 2,5,6,100,45,51

Output
--------

Colum1| Column 2

123456|2
123456|5
123456|6
123456|100
123456|45
123456|51

I know with transformer loop option, I can create multiple rows from single row, but no idea how I can get individual value in column2 for each record. I think it might have worked with a pivot stage if the maximum number of comma in second column is known. But I unfortunately the comma in Column2 is no upper cutoff, In other words I do not have a clue on the number of values in column2.

Really sorry if It is a repeat question, I cannot find answer when I searched. Please share the link if this is already discussed

Any help is greatly appreciated !!
Thanks,
Sham
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

No, do use a loop. There are examples documented. Create a stage variable containing the number of delimited fields (use DCount() function, for example). Loop exit condition is

Code: Select all

 @ITERATION <= svNumberOfFields
Within the loop, extract an individual field using

Code: Select all

Field(in.Column, delimiter, @ITERATION, 1)
For example, Field(in.Column2, ",", @ITERATION, 1)
Load this into a loop variable and use that to provide the value of the output field. The second example in this IBM Knowledge Center article will provide a similar explanation.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Sham9
Participant
Posts: 7
Joined: Wed Nov 09, 2016 11:34 pm

Post by Sham9 »

Thank you Ray!

My bad, I never thought about @ITERATION option. Thank you very much.It is working for me.
Thanks,
Sham
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Pardon a (perhaps) silly question but I'm curious about transformer looping and how one controls that. Is there some other way rather than using @ITERATION to control how many times to loop? :?
-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 »

Any expression.

For example a constant 10 if you always have 10 delimited fields.

But @ITERATION is there, and singularly useful.

Other techniques would be appropriate in the "filling in the gaps in a sequence of dates/numbers" scenarios.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply