Cancel Oracle Trigger to Execute The Commands


Hi, I want to cancel the trigger of a table that does not work if the logic condition is not met. So as if I want the trigger to rollback (for example = cancel delete in before-delete trigger). At first, the trigger like this :

CREATE OR REPLACE TRIGGER MIS.TRIG01_TABLE_A
BEFORE DELETE
ON PANDAZEN.TABLE_A
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
BEGIN
INSERT INTO PANDAZEN.TABLE_B
SELECT * FROM PANDAZEN.TABLE_A;
END;

The trick to achieve what I want, ie – cancel delete command in the before-delete trigger is to use the command

raise_application_error

So, now triggernya be like this :

CREATE OR REPLACE TRIGGER MIS.TRIG01_TABLE_A
BEFORE DELETE
ON PANDAZEN.TABLE_A
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
BEGIN
IF (:OLD.TABLE_A_VALUE = ‘OLD’) THEN
RAISE_APPLICATION_ERROR (-20000, ‘CANCEL DELETE’);
END IF;

INSERT INTO PANDAZEN.TABLE_B
SELECT * FROM PANDAZEN.TABLE_A;
END;

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: