Sequence generated in DB2

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
Abhyankar
Participant
Posts: 15
Joined: Thu Jan 01, 2009 11:04 pm

Sequence generated in DB2

Post by Abhyankar »

Hi,
I have generated a Sequence in DB2. How can i import or use it in Datastage? I want to use it as a key generator in my Job.
amritendra
Participant
Posts: 2
Joined: Mon Aug 04, 2008 11:54 pm
Location: kolkata

Re: Sequence generated in DB2

Post by amritendra »

Abhyankar wrote:Hi,
I have generated a Sequence in DB2. How can i import or use it in Datastage? I want to use it as a key generator in my Job.
Hi In target DB2 stage You can use option user defiened update and insert . Then you can assign value like below.

INSERT INTO
schema name .Table name
(
Key field

)
VALUES
(
NEXTVAL FOR schema name .Sequence name

)
amritendra kumar
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Re: Sequence generated in DB2

Post by ray.wurlod »

Abhyankar wrote:Hi,
I have generated a Sequence in DB2. How can i import or use it in Datastage? I want to use it as a key generator in my Job.
You can use its NEXTVAL property in any SELECT, including on a reference link. Just don't expected it to be fast.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Abhyankar
Participant
Posts: 15
Joined: Thu Jan 01, 2009 11:04 pm

Post by Abhyankar »

Thanks i did that. I changed the property to 'User defined Sql'. However i had other columns also, so i changed my target syntax as:

INSERT INTO
schema name .Table name
(
Key field,col1,col2

)
VALUES
(
NEXTVAL FOR schema name .Sequence name,?,?

)


My Job is aborting saying below:

" Fatal Error: Fatal: This SQL statement did not contain the same number of parameters as columns on this link. This usually happens with user-defined SQL. "

The number of columns are correct.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

How many columns in your design? You only have two parameter markers, so you require precisely two columns in the design. Specifically you do not include the name of the key column in your design. Just col1 and col2.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Abhyankar
Participant
Posts: 15
Joined: Thu Jan 01, 2009 11:04 pm

Post by Abhyankar »

Hi,
i didnt understand= 'Specifically you do not include the name of the key column in your design.'

Am i not supposed to add my key column (The one i am doing NEXTVAL with ) in the columns property of my DB2 stage?
tehavele
Premium Member
Premium Member
Posts: 79
Joined: Wed Nov 12, 2008 5:41 am
Location: Melbourne

Post by tehavele »

Abhyankar wrote:Hi,
i didnt understand= 'Specifically you do not include the name of the key column in your design.'

Am i not supposed to add my key column (The one i am doing NEXTVAL with ) in the columns property of my DB2 stage?


It means

Code: Select all

INSERT INTO 
schema name .Table name 
( 
col1,col2 

) 
VALUES 
( 
NEXTVAL FOR schema name .Sequence name,?,? 

) 
Remove key_field name from stage defination's as well.
Tejas
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

The key column does need to be in the columns list of your user-defined SQL, but NOT on the Columns tab of your input link, because DataStage is not providing the value for the key column.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Abhyankar
Participant
Posts: 15
Joined: Thu Jan 01, 2009 11:04 pm

Post by Abhyankar »

Thanks everyone. The problem is solved now.
Post Reply