I have two tables- XX
and YY
with their triggers calling each other in case of an update.
The trigger on XX goes like this:
CREATE OR REPLACE TRIGGER SCMA.XX_RBIU
BEFORE INSERT OR UPDATE
ON SCMA.XX FOR EACH ROW
-- PL/SQL BLOCK
BEGIN
IF UPDATING THEN
-- Only update the YY row if the branch id has
-- been modified on the XX row
IF :NEW.BRANCH_ID <> :OLD.BRANCH_ID THEN
UPDATE YY TP
SET TP.BRANCH_ID = :NEW.BRANCH_ID
WHERE TP.XX_ID = :NEW.XX_ID;
END IF;
END IF;
...
... -- Other PL/SQL statements that do some necessary
... -- computation and do not use any SQL.
...
END;
/
And the trigger on YY goes like this:
CREATE OR REPLACE TRIGGER SCMA.YY_RBIU
BEFORE INSERT OR UPDATE
ON SCMA.YY
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
DECLARE
v_xx_type xx.xx_type_code%TYPE;
BEGIN
select x.xx_type_code
into v_xx_type
from XX x
where x.xx_id = :new.xx_id;
...
... -- Other PL/SQL statements that do some necessary
... -- computation and do not use any SQL.
...
END;
/
I know that the SELECT
statement in the trigger YY_RBIU
is giving this error. How can I code my triggers in order to avoid it?
I tried to wrap the SELECT
statement in YY_RBIU
inside an IF INSERTING THEN
block but this does not run for any updates. How can I skip this SELECT
statement if update is being called from trigger XX_RBIU
?
I also tried putting PRAGMA AUTONOMOUS_TRANSACTION
in XX_RBIU
but it is resulting into a deadlock.
I also tried referring to this, this, this and this but couldn't get a solution.
Any help is much appreciated.