Re: How to retrieve a SERIAL value in a STORED PROCEDURE
Posted in 1995
Etienne,
In version 7.10 the DBINFO() expression was introduced. So, within
a stored procedure, you can get the serial number (immediately after
the insert) with the statement:
LET var = DBINFO('sqlca.sqlerrd2');
Also available are DBINFO('sqlca.sqlerrd1') and DBINFO('DBSPACE', tblspacenum).
It's possible that DBINFO appeared earlier than 7.1. I skipped directly
from version 5 to 7.10 so I don't know what did or didn't appear in 6.
Before 7.10 there was a method where you wrapped your insert table in
a trigger which then executed a stored procedure that set a global
variable to the value of the inserted row's serial value. It was pretty
obscure though. If you need the details/examples of how to do that
(because you aren't on 7.10) let me know and I'll see what I can do.
--Craig (craig@chemistry.utah.edu)
>
> Hello,
>
> Is there a solution to retrieve the SERIAL number after an INSERT
> in a STORED PROCEDURE as far as the SQLCA.SQLERRD[2] does not works.
>
> Is there a better solution than this one :
>
> set lock mode ...
> lock table in share mode
> insert into zob ( num ) values ( 0 ) <------ num : serial> select max(num) into var from zob
> commit work
>