If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Stored procedure return primary key of inserted row ?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-23-10, 02:35
asp_crazy_guy asp_crazy_guy is offline
Registered User
 
Join Date: Mar 2009
Posts: 73
Stored procedure return primary key of inserted row ?

Hello guys, I want a stored procedure to return the primary key of the new record after it gets executed. I think it will be returned by OUT parameter in the procedure. But how to select the newly inserted row ID ? I don't want to use select MAX(row_id) as it is a multi user environment. Any procedure sample will be appreciated.

The row id Column is not an identity column. It uses a sequence for the key which gets generated via a trigger before insert on table.

My platform is ISeries DB2 V5 R4. Thanks.
Reply With Quote
  #2 (permalink)  
Old 07-26-10, 09:27
tonkuma tonkuma is online now
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,195
If you upgraded to DB2 for i Version 6 Release 1, you would be able to use data-change-table-reference.

Like:
SELECT row_id FROM FINAL TABLE ( INSERT statement );

But, I don't know anyway for DB2 for i5/OS Version 5 Release 4.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On