Subject | Re: [ib-support] using Gen_id from a stored proc |
---|---|
Author | Jörg Schiemann |
Post date | 2001-03-21T18:47:02Z |
> I am trying to write a simple stored proc that returns the results ofTry
> running Gen_Id. I am trying to use this code:
>
> Create Procedure GeneratePrimaryKey
> Returns ("PK" Integer )
> As Begin
> "PK" = Gen_Id( PrimaryKeyGenerator, 1 );
> End !!
> Set Term ; !!
>
> I execute this code using both of these:
>
> Execute Procedure GeneratePrimaryKey
> Select PK From GeneratePrimaryKey
>
> However, though the PrimarykeyGenerator value is being incremented with
> both approaches, neither of these approaches are actually returning the
> generated value. I get back a table with one column and no data.
>
> Does anyone have any idea what I am doing wrong?
>
> Thanks,
> Rhett
DECLARE VARIABLE GEN_NO INTEGER;
DECLARE VARIABLE GEN_NEXT_NO INTEGER;
SELECT GEN_ID(GEN_YOUR_GENERATOR, 0) FROM RDB$DATABASE INTO :GEN_NO;
GEN_NEXT_NO = GEN_NO + 1;
HTH,
Jörg