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 > DB2 equivelant of MySQL's mysql_insert_id() C function

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-03-07, 11:56
Fumigator Fumigator is offline
Registered User
 
Join Date: Mar 2007
Posts: 24
DB2 equivelant of MySQL's mysql_insert_id() C function

When a key is defined auto-increment in MySQL, you can grab the newly inserted ID just after an insert query via the mysql_insert_id() C function.

With DB2's "GENERATED ALWAYS" keyword on a column, is there a way to grab a newly inserted ID other than a select query on the row I just inserted?

(DB2 V.8 I believe, on zO/S)
Reply With Quote
  #2 (permalink)  
Old 07-03-07, 14:42
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
You can use the IDENTITY_VAL_LOCAL function or just select from the insert:
Code:
SELECT ...
FROM NEW TABLE ( INSERT ... ) AS t
p.s: You should be sure about the platform your are working on. The correct answer may depend on that because not all features are available no all DB2 flavors yet. Running "db2 connect" on the command line tells you the server's platform.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #3 (permalink)  
Old 07-03-07, 18:10
Fumigator Fumigator is offline
Registered User
 
Join Date: Mar 2007
Posts: 24
It's V.8 for sure... CICS/COBOL environment. Thanks for the answer. A search of that function in the DB2 docs I found this, which worked a treat:

Code:
EXEC SQL
    VALUES IDENTITY_VAL_LOCAL() INTO :IVAR;
END-EXEC
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