Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: Raising an Exception when a Constraint is Violated

Re: Raising an Exception when a Constraint is Violated

From: Ken Denny <ken_at_kendenny.com>
Date: Tue, 18 Jun 2002 18:04:53 GMT
Message-ID: <Xns92318FEFC4319kendenny@65.82.44.7>


"Aaron Jaque" <aaron.jaque_at_cybersurf.net> wrote in news:3d0f7568$1_2_at_news.cybersurf.net:

> I'm trying to raise an exception when an integrity constraint is
> violated. I can catch the error with the "WHEN OTHERS" exception, but I
> want to catch the specific error individually. The error looks like
> this: ERROR at line 1:
> ORA-02291: integrity constraint (SCHEMA_NAME.CONSTRAINT_NAME) violated
> - parent key not found
> ORA-06512: at "SCHEMA_NAME.PACKAGE_NAME", line 82
> ORA-06512: at line 1
>
> Is there a way to catch this specific error, maybe by number?

DECLARE
   parent_not_found EXCEPTION;
   PRAGMA EXCEPTION_INIT (parent_not_found, -2291); BEGIN
   ...
EXCEPTION
   WHEN parent_not_found THEN
   ...
END; This defines the exception name Parent_not_found and associates it with the error number -2291. You can then use the exception name in your EXCEPTION section.

-- 
Ken Denny
http://www.kendenny.com/

42.7 percent of all statistics are made up on the spot.
Received on Tue Jun 18 2002 - 13:04:53 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US