Re: Catching Constraint Violations in PL/SQL

From: Sybrand Bakker <postbus_at_sybrandb.demon.nl>
Date: 13 Mar 2003 06:50:58 -0800
Message-ID: <a20d28ee.0303130650.77b8f9ee_at_posting.google.com>


martin_bach_at_t-online.de (Martin Bach) wrote in message news:<d1bc17cb.0303130242.4274e8a2_at_posting.google.com>...
> Hi there!
>
> Is there a standard way to catch a constraint violation on PL/SQL?
> I've got something like this:
>
> declare
> ...
> begin
> constraint_violation( a,b,c);
>
> exception
> when others then
> ...
> end;
>
> In the docs, I found a few predefined exceptions (like ZERO_DIVIDE),
> but no CONSTRAINT_VIOLATED or something similar. DBMS_STANDARD does
> not define this either, and "PRAGMA EXCEPTION_INIT()" is for user
> defined exceptions only. So which way is there to catch a constraint
> violation?
>
> TIA,
>
> Martin Bach

Pragma exception_init is *NOT* for user_exceptions *ONLY*. It is quite easy to bind an user-defined name to an Oracle error number You don't mention dup_val_on_index for ora-0001 which you could also readily use.

Regards

Sybrand Bakker
Senior Oracle DBA Received on Thu Mar 13 2003 - 15:50:58 CET

Original text of this message