IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

DB2 z/OS: IDENTITY_VAL_LOCAL() in SQL PL


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Auryn

New User


Joined: 11 Jan 2006
Posts: 83
Location: Lower Saxony (DE)

PostPosted: Mon Nov 19, 2012 3:16 pm
Reply with quote

I just have learned I can use the function IDENTITY_VAL_LOCAL to retrieve the last given value of a identity-column of a table.
And I have learned that this function only works in one UoW and that there must not be a commit or something like that before using the function.
But if I do a Insert in a SQL-PL-written stored procedure, may I check SQL-State and / ore -Code before retrieving the functions result?
May I code
Code:
INSERT INTO tab (col2, col3)
         VALUES (val2, val3);
IF SQLSTATE = '00000'
THEN
     SET id_col = IDENTITY_VAL_LOCAL()
     ...
ELSE
     ...
END IF;

Thanks for your help
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Mon Nov 19, 2012 9:40 pm
Reply with quote

you can always try and tell us the result icon_smile.gif
or write this :
Code:
SELECT id_col into val1
  FROM FINAL TABLE (INSERT INTO TB1 (col2, col3)
                 VALUES(val2, val3))
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Search our Forums:

Back to Top