Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error handling inside Triggers

Status
Not open for further replies.

KingElves

Programmer
Oct 30, 2000
1
PT
Hello.
I'm trying to use a "raise_application_error" inside a trigger to halt all execution and return an error. It's not working though, here is what i got:

CREATE OR REPLACE TRIGGER iva_trigger
BEFORE
INSERT OR UPDATE OF cat_iva,descrição,imposto ON Iva FOR EACH ROW

DECLARE

...
...
IF (cat_aux=:new.cat_iva) THEN
RAISE categoria_existente;
END IF;
EXCEPTION
WHEN categoria_existente THEN
RAISE_APPLICATION_ERROR(-20001,'....');

This trigger is being called by a function i defined in a package, just before an INSERT command. The problem is, instead of halting execution, it returns to the aforementioned function, and tries to execute the INSERT command.
Obviously, i don't want to execute this INSERT, since it will violate a PRIMARY KEY constraint.
Why isn't this EXCEPTION working?
How do i do it?

Thanks all!
 
My recent work with exceptions using systems error codes has shown me that i need to declare the exception using PRAGMA EXCEPTION before i can use it eg :

--********************************************************
--Added by ... 9 Oct 2000

e_Legacy EXCEPTION; -- error handler for multiple legacy client numbers
PRAGMA EXCEPTION_INIT(e_Legacy, -1422); -- tie error handler to
-- ORA-01422: exact fetch returns more than requested number of rows

e_LegacyClntNo EXCEPTION; -- error handler for unique constraint violation
PRAGMA EXCEPTION_INIT(e_LegacyClntNo, -1); -- tie error handler to ORA-01
--**************************************************************

Would this be the case for your particular requirements ?
Best of Irish Luck, David.
djwilkes@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top