How do you use SQL insert to insert the correctly sequenced Primary ID to a table row?
Answers5
AC
AC2020-02-21
You can do this in a similar way to other SQL clients:
insert into mytable (id, column1, column2) values(mysequence.nextval,?,?);
And then map the values of column1 and column2 and so on to properties on the incoming data record. I hope this helps.
KE
KE2020-02-21
HI, thanks for the reply. I do know how to set up the component to do the insert but the issue is inserting the row id which is a sequenced value. Using the max(id) +1 as the starting value doesn't work and neither does nextval. Looking for specific help on how to overcome that issue. Thanks again!
MH
MH2020-02-21
You can place a "SQL Select for Each Data" component upstream where you increment the sequence and assign the number to a PP property MyID: select mysequence.nextval MyID from dual
AC
AC2020-02-24
Do you have a sequence defined in the database already for this primary ID?
DB
DB2020-02-24
The mysequence.nextval approach as suggested by Andrei actually should work and works in my test system. Can you possibly add some details on how it fails in your system (e.g. output from the fail port of the SQL Insert component).
With regard to the max(id) approach, the INSERT statement in the component is a bit different (as it is in native Oracle). The max(id) is an aggregate function which can only be used within a SELECT statement. Accordingly, the INSERT statement must embedd a subselect statement to fetch the max(id) value:
INSERT into MYTABLE (id, column1, column2) VALUES ((select max(id)+1 from MYTABLE), ?, ?)
You can do this in a similar way to other SQL clients:
insert into mytable (id, column1, column2)
values(mysequence.nextval,?,?);
And then map the values of column1 and column2 and so on to properties on the incoming data record.
I hope this helps.
HI, thanks for the reply. I do know how to set up the component to do the insert but the issue is inserting the row id which is a sequenced value. Using the max(id) +1 as the starting value doesn't work and neither does nextval. Looking for specific help on how to overcome that issue. Thanks again!
You can place a "SQL Select for Each Data" component upstream where you increment the sequence and assign the number to a PP property MyID: select mysequence.nextval MyID from dual
Do you have a sequence defined in the database already for this primary ID?
The mysequence.nextval approach as suggested by Andrei actually should work and works in my test system. Can you possibly add some details on how it fails in your system (e.g. output from the fail port of the SQL Insert component).
With regard to the max(id) approach, the INSERT statement in the component is a bit different (as it is in native Oracle). The max(id) is an aggregate function which can only be used within a SELECT statement. Accordingly, the INSERT statement must embedd a subselect statement to fetch the max(id) value:
INSERT into MYTABLE (id, column1, column2)
VALUES ((select max(id)+1 from MYTABLE), ?, ?)