How to get the value of a sequence from an Oracle stage.

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
Minhajuddin
Participant
Posts: 467
Joined: Tue Mar 20, 2007 6:36 am
Location: Chennai
Contact:

How to get the value of a sequence from an Oracle stage.

Post by Minhajuddin »

Hi all,
I have a job which has 10 input columns and inserts these columns into a table and a file. Now Before I insert it into a table and a file. I add another column which is a unique no. I generate this no. from a sequence in Oracle. I tried getting this unique no by this query "select seq.nextval from dual" in a DB stage and then looking it up in the transformer. But It didn't work. Because there was no key column I was looking up to. I am really stuck here. Do you guys have any idea as to how to go about it.

I want to insert values with a sequence in a table and a flat file.

Please help me out.

Thanks a lot.
Minhajuddin

<a href="http://feeds.feedburner.com/~r/MyExperi ... ~6/2"><img src="http://feeds.feedburner.com/MyExperienc ... lrow.3.gif" alt="My experiences with this DLROW" border="0"></a>
maheshsada
Participant
Posts: 69
Joined: Tue Jan 18, 2005 12:15 am

Post by maheshsada »

In in your input column, select a dummy column, Name - Dummy value - '1'.
When the sequence is generated - use the below query
select seq.nextval, '1' dummy1 from dual

Now you can use the dummy column as key column in transformer

regards
Magesh S
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Why do you have to do a lookup again? Can't you get the seq.nextval in your source itself?
Something like

Code: Select all

select A.Col1, A.Col2, A.Col3, (select seq.nextval from dual) AS Unique_No from Table A
Possible ???
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

If this really is a parallel job as you have indicated there may be more issues with your approach. Will you execute this query on each processing node? In that case you will retrieve different values.

Do you really need to get the value? Why not just incorporate the reference to the sequence in user-defined INSERT statement?

Code: Select all

INSERT INTO table(c1,c2,c3) VALUES (seqname.NEXTVAL,:1,:2)
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Minhajuddin
Participant
Posts: 467
Joined: Tue Mar 20, 2007 6:36 am
Location: Chennai
Contact:

Post by Minhajuddin »

Hi
My source is a text file and not a DB.
So I can't use a

select A.Col1, A.Col2, A.Col3, (select seq.nextval from dual) AS Unique_No from Table A

Any other ideas...
Minhajuddin

<a href="http://feeds.feedburner.com/~r/MyExperi ... ~6/2"><img src="http://feeds.feedburner.com/MyExperienc ... lrow.3.gif" alt="My experiences with this DLROW" border="0"></a>
Minhajuddin
Participant
Posts: 467
Joined: Tue Mar 20, 2007 6:36 am
Location: Chennai
Contact:

Post by Minhajuddin »

maheshsada wrote:In in your input column, select a dummy column, Name - Dummy value - '1'.
When the sequence is generated - use the below query
select seq.nextval, '1' dummy1 from dual

Now you can use the dummy column as key column in transformer

regards
Magesh S

Are you talking about doing a lookup? If it is a lookup which column do you think we should make as the key column, And this key column should be true once for each record.........

Can you elaborate on this Mahesh..................
Minhajuddin

<a href="http://feeds.feedburner.com/~r/MyExperi ... ~6/2"><img src="http://feeds.feedburner.com/MyExperienc ... lrow.3.gif" alt="My experiences with this DLROW" border="0"></a>
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

A Server lookup does not need a Key field to work, but a hard-coded dummy value will also work.
-craig

"You can never have too many knives" -- Logan Nine Fingers
narasimha
Charter Member
Charter Member
Posts: 1236
Joined: Fri Oct 22, 2004 8:59 am
Location: Staten Island, NY

Re: How to get the value of a sequence from an Oracle stage.

Post by narasimha »

Minhajuddin wrote:I tried getting this unique no by this query "select seq.nextval from dual" in a DB stage and then looking it up in the transformer. But It didn't work.
You could pass the link from the DB stage you are using as a lookup into the column, where you want the Oracle sequence number.
That should work for you.
Narasimha Kade

Finding answers is simple, all you need to do is come up with the correct questions.
Minhajuddin
Participant
Posts: 467
Joined: Tue Mar 20, 2007 6:36 am
Location: Chennai
Contact:

Post by Minhajuddin »

Hi all,
Thank you Chulett.
Initially I was under the impression that the key to the lookup has to be linked to the source file. Now I have hardcoded it, and its working fine.

Thank you all,
:D:D:D
:D:D:D
:D:D:D
Minhajuddin

<a href="http://feeds.feedburner.com/~r/MyExperi ... ~6/2"><img src="http://feeds.feedburner.com/MyExperienc ... lrow.3.gif" alt="My experiences with this DLROW" border="0"></a>
jreddy
Premium Member
Premium Member
Posts: 202
Joined: Tue Feb 03, 2004 5:09 pm

Post by jreddy »

Your design is like this SF ->Transformer-> Oracle stage. In the transformer, add a dummy column SEQ_ID and set it to a default value of 1. Then in the target stage, go to the SQL code and from the SELECT statement generated, replace the text 'ORCHESTRATE.SEQ_ID' (something like that - that is generated for this dummy column) with oracleSeq.nextval
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Besides the fact that this topic is 'Resolved' did you miss the requirement where the sequence's value needs to go to two targets?
-craig

"You can never have too many knives" -- Logan Nine Fingers
Minhajuddin
Participant
Posts: 467
Joined: Tue Mar 20, 2007 6:36 am
Location: Chennai
Contact:

Re: How to get the value of a sequence from an Oracle stage.

Post by Minhajuddin »

Minhajuddin wrote: I want to insert values with a sequence in a table and a flat file.

Please help me out.

Thanks a lot.
Hi Chulett,
I did mention that the sequence value needs to go to two targets. But maybe I was not able to communicate it properly. And as you said I hardcoded the value of the key column and it's working fine. Do we have any other way to do this?

Thank you.
Minhajuddin

<a href="http://feeds.feedburner.com/~r/MyExperi ... ~6/2"><img src="http://feeds.feedburner.com/MyExperienc ... lrow.3.gif" alt="My experiences with this DLROW" border="0"></a>
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Minhajuddin, you did fine. I know you mentioned that - I was actually pointing that fact out to jreddy. Their solution is fine as long as you don't need to know the sequence number that was generated. When you do - as in your case - you have to 'pull' it beforehand.
-craig

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