Oracle sequence for getting the value
Moderators: chulett, rschirm, roy
Oracle sequence for getting the value
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 in advance
Thanks in advance
Rather than select it on every row (which you could do via a lookup) I would just use custom sql. Pass all columns except the sequence field to the target stage, let it generate the DML and then modify it to include the sequence field with a value of SEQ_NAME.NEXTVAL which tells the insert DML to automagically fetch the next value.
-craig
"You can never have too many knives" -- Logan Nine Fingers
"You can never have too many knives" -- Logan Nine Fingers
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
You can do that. Use user-defined SQL in the Oracle stage that provides rows to the reference input. Pass a constant (say 'X') as the "key" and, basically, ignore it in the Oracle stage.
Code: Select all
SELECT sequence.NEXTVAL AS NEXTKEY from DUAL WHERE :1 = 'X'
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
OK, that only changes my answer slightly. After the lookup, branch out two links from a transformer - one for records where the lookup succeeded and another for where it failed. For the former, process as normal (I've been assuming an insert follows). For the latter, process as indicated previously.
Or alternately do another lookup to retrieve the NEXTVAL only as part of the second link.
Or alternately do another lookup to retrieve the NEXTVAL only as part of the second link.
-craig
"You can never have too many knives" -- Logan Nine Fingers
"You can never have too many knives" -- Logan Nine Fingers
Perform a lookup
1. For the matched rows, Lookup will provide the ID (Say in Link A)
2. For the unmatched rows, capture the Rejects in the reject link.
2.1 Use a surrogate key generator stage and select the property
- Source Type as "Database Sequence"
- Generated Output Column Name as "your ID column"
- Source Name as "SEQ_NAME.NEXTVAL"
2.2 Output of the Surrogate key will have the new ID generated for the unmatched rows (Say in Link B)
3. Use a funnel to merge the records from Link A and Link B
4. Output of the Funnel will have ID generated for the unmatched rows and ID looked up for the matched rows.
1. For the matched rows, Lookup will provide the ID (Say in Link A)
2. For the unmatched rows, capture the Rejects in the reject link.
2.1 Use a surrogate key generator stage and select the property
- Source Type as "Database Sequence"
- Generated Output Column Name as "your ID column"
- Source Name as "SEQ_NAME.NEXTVAL"
2.2 Output of the Surrogate key will have the new ID generated for the unmatched rows (Say in Link B)
3. Use a funnel to merge the records from Link A and Link B
4. Output of the Funnel will have ID generated for the unmatched rows and ID looked up for the matched rows.
Rgrds,
Abhi
Abhi