Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

DB2 z/OS: IDENTITY_VAL_LOCAL() in SQL PL

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
Auryn

New User


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

PostPosted: Mon Nov 19, 2012 3:16 pm    Post subject: DB2 z/OS: IDENTITY_VAL_LOCAL() in SQL PL
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    Post subject:
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    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:



Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us