I have 2 insert triggers, that fire on same table, they both try to alter table row content and then happens collision, or my sql developer starts endless execution of the commands, and then I need to restart DB. How to fix that? Should I merge those 2 triggers into 1 trigger? Or should try to control firing order with this command:
execute immediate 'alter trigger trigger_name disable';
execute immediate 'alter trigger trigger_name enable';
or should I use trigger inside of trigger.. please I want expert opinion about this one.. im in big dilema right now, since this is the first time I do PL/SQL coding.
EDIT: HERE ARE THE TRIGGERS WITH WHICH I WORK ON:
create or replace
TRIGGER TRG_PROCED_SN_INS_CENA
AFTER INSERT ON STAVKA_NARUDZBENICE
FOR EACH ROW
DECLARE
pragma autonomous_transaction;
sifra_narudzbenice NUMBER;
BEGIN
paket_sn_sifnar.sifra_narudzbenice := :NEW.sifra_narudzbenice;
pStavkaNarudzbeniceInsert(paket_sn_sifnar.sifra_narudzbenice);
COMMIT;
END;
/
create or replace
TRIGGER TRG_SN_INS_UPD_NAZIV
AFTER INSERT ON Stavka_narudzbenice
FOR EACH ROW
FOLLOWS TRG_PROCED_SN_INS_CENA
DECLARE
v_naziv_proizvoda VARCHAR2(25);
v_cena NUMBER;
BEGIN
SELECT naziv_proizvoda INTO v_naziv_proizvoda
FROM proizvod
WHERE sifra_proizvoda=:NEW.sifra_proizvoda;
SELECT cena INTO v_cena
FROM stavka_kataloga
WHERE sifra_proizvoda=:NEW.sifra_proizvoda;
UPDATE stavka_narudzbenice
SET naziv_proizvoda = v_naziv_proizvoda, cena = v_cena WHERE sifra_proizvoda =:NEW.sifra_proizvoda;
END;
/
In 11G you can control the order of triggers using the FOLLOWS clause. For example:
i.e. There are 2 triggers trg1 and trg2 that both fire after insert on table EMP, and we have declared that trg2 should fire after (follow) trg1.