Oracle Sequence

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
jherr22
Premium Member
Premium Member
Posts: 56
Joined: Mon Jan 29, 2007 3:24 pm
Location: Denver
Contact:

Oracle Sequence

Post by jherr22 »

I need to get a sequence number from an Oracle sequence to use in my job. I can modify the insert/update statement in an Oracle stage to insert a sequence number, but I need that number in other stages (we are populating many tables with the same sequence number). I need to use the sequence instead of the surrogate key generator. Any suggestions for getting an Oracle sequence number to use in a job?
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Do a sparse lookup, ping the sequence object and get the next key. Then save it, use it, do whatever you have to.
I do something similar in db2.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
richclee
Participant
Posts: 2
Joined: Tue Dec 19, 2006 1:59 am
Location: North East UK

Post by richclee »

SELECT sequence_name.CURRVAL FROM dual
If you run this select, it will return the current value of the Oracle Sequence.

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

Post by chulett »

Which doesn't help all that much as you really want to select the NEXTVAL so it gets incremented properly.
-craig

"You can never have too many knives" -- Logan Nine Fingers
jherr22
Premium Member
Premium Member
Posts: 56
Joined: Mon Jan 29, 2007 3:24 pm
Location: Denver
Contact:

Post by jherr22 »

[quote="DSguru2B"]Do a sparse lookup, ping the sequence object and get the next key. Then save it, use it, do whatever you have to.
I do something similar in db2.[/quote]

I need to get the nextval and join it with every row of an input file, in other words, each row of the input file needs to have a new nextval value joined to it. Will a sparse lookup do that? Are you able to point me to an example?

Thanks for your help!
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

No, a sparse lookup will get the next value and the next value and the next value...

To get just one next value you can use a regular lookup (probably with Entire partitioning). Provide a constant in an additional column against which you can effect a faux comparison.

Code: Select all

SELECT 1,sequence.NEXTVAL FROM DUAL 
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 »

ray.wurlod wrote:a sparse lookup will get the next value and the next value and the next value...
Pretty sure that's what they want. :?
jherr22 wrote:in other words, each row of the input file needs to have a new nextval value joined to it.
-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 »

Yet
jherr22 wrote:I need to get the nextval and join it with every row of an input file
could be read the other way.
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 know. Hence the :?
-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 »

:? indeed!
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
jherr22
Premium Member
Premium Member
Posts: 56
Joined: Mon Jan 29, 2007 3:24 pm
Location: Denver
Contact:

Post by jherr22 »

Sorry to be so vague.

Here is what I need in more detail. For every row from my input dataset, I need to add a column that has the nextval from my oracle sequence. So, for example, I need to join row 1 of my dataset with sequence.nextval, row2 with sequence.nextval, row3 with sequence.nextval and soforth, where sequence.nextval will be different (of course) with each row.

Thanks again for all your help - I am relatively new with Data Stage, and this problem has us stumped.
jherr22
Premium Member
Premium Member
Posts: 56
Joined: Mon Jan 29, 2007 3:24 pm
Location: Denver
Contact:

Post by jherr22 »

Sorry to be so vague.

Here is what I need in more detail. For every row from my input dataset, I need to add a column that has the nextval from my oracle sequence. So, for example, I need to join row 1 of my dataset with sequence.nextval, row2 with sequence.nextval, row3 with sequence.nextval and soforth, where sequence.nextval will be different (of course) with each row.

Thanks again for all your help - I am relatively new with Data Stage, and this problem has us stumped.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Has or had? Sparse lookup.
-craig

"You can never have too many knives" -- Logan Nine Fingers
jherr22
Premium Member
Premium Member
Posts: 56
Joined: Mon Jan 29, 2007 3:24 pm
Location: Denver
Contact:

Post by jherr22 »

Thank you all for your help - you guys rock!

I did not realize that the sparse lookup was an option in the Oracle stage - I was looking in the lookup stage. Works great now!

Thanks!
Post Reply