Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Is there a way to conitionaly fire triggers ??
Consider this:
When you want to delete the row permanently, just delete the row in the mirror table instead of the primary table. In order for this to work, you need to do two things:
This way, when you delete from the primary it will copy the row into the mirror. When you delete from the mirror, it will delete the row from the primary, which will cause the primary's delete trigger to try to insert a row into the mirror, which will fail due to a table mutatation error, but you throw away the error (but raise all other errors so you still catch any real problems).
Make sure you put only the "copy to mirror" logic in the catch block, so other statements can execute normally. Also, if there is any cascade-delete logic you want to put in primary, and this cascades to other tables with the same "backup" behavior, you'll want to put the same cascade logic in the mirror tables so deletes cascade correctly.
CREATE TRIGGER tD_primary after delete on primary for each row
BEGIN
BEGIN
INSERT INTO mirror VALUES (:old.col1, :old.col2, ...); EXCEPTION WHEN OTHERS THEN IF SQLCODE = -4091 THEN -- This is a table mutation error. Ignore it since -- it will happen when we delete this row from the -- mirror's delete trigger NULL; ELSE RAISE; END IF;
--== Sent via Deja.com http://www.deja.com/ ==-- ---Share what you know. Learn what you don't.--- Received on Tue May 18 1999 - 18:54:31 CDT
![]() |
![]() |