Subject Re: [firebird-support] Handling Exceptions in Stored Procedures
Author Helen Borrie
At 02:52 AM 5/05/2005 +0000, you wrote:
>Is there an Example . Itried the following and I could not get it to
>compile.
> Any Ideas?

Yup. There is no syntax "WHEN EXCEPTION".

>CREATE PROCEDURE PROC_INJECT_PLUSALES
>(
> ASTOREID VARCHAR(10),
> ASALESDATE TIMESTAMP,
> APLU VARCHAR(14),
> AQUANTITYSOLD FLOAT,
> ASALESEXGST FLOAT,
> ACOSTEXGST FLOAT,
> ASALESINCGST FLOAT,
> ACOSTINCGST FLOAT
>)
>AS
>BEGIN
> INSERT INTO PLUSALES
> ( STOREID, SALESDATE, PLU,
> QUANTITYSOLD, SALESEXGST,
> COSTEXGST, SALESINCGST, COSTINCGST )
> VALUES
> ( :ASTOREID, :ASALESDATE, :APLU,
> :AQUANTITYSOLD, :ASALESEXGST,
> :ACOSTEXGST, :ASALESINCGST, :ACOSTINCGST );


> /* WHEN EXCEPTION DO */

WHEN GDSCODE unique_key_violation DO

> BEGIN
> UPDATE PLUSALES
> SET
> QUANTITYSOLD = :AQUANTITYSOLD,
> SALESEXGST = :ASALESEXGST,
> COSTEXGST = :ACOSTEXGST,
> SALESINCGST = :ASALESINCGST,
> COSTINCGST = :ACOSTINCGST
> WHERE
> ( STOREID = :ASTOREID )AND
> ( SALESDATE = :ASALESDATE )AND
> ( PLU = :APLU );
> END
>END;

Study Chapter 32 of The Firebird Book, or read up on the little there is in
DataDef.pdf. If you don't have TFB, you can pick up all the gdscodes from
the Knowledgebase section of the main website (see tail message below).

./hb