jeudi 19 décembre 2019

How can I trigger a delete action on a table with an if-statement?

I'm developing this trigger for a personal project and I'm not sure what I'm doing wrong. The trigger compiles fine and, testing what the trigger is supposed to do, it works ... but the condition isn't working. The trigger just does nothing

Here's my code

CREATE OR REPLACE TRIGGER z_delete
BEFORE INSERT or UPDATE OR INSERT OF status ON TABLE_1
FOR EACH ROW


BEGIN
IF (:new.condition_1 = 'I' or :new.condition_2 ='Z')
  THEN

  DELETE TABLE_2 WHERE EXISTS
    (SELECT * FROM TABLE_1 WHERE TABLE_1.Value_1 = TABLE_2.Value_2 AND TABLE_1.condition_1='I');


  DELETE interference_results WHERE EXISTS
    (SELECT * FROM TABLE_1 WHERE TABLE_1.Value_1 = TABLE_2.Value_3 AND TABLE_1.condition_1 = 'I');

END IF;

END z_delete;

Anyone has any idea whats going on??

Thanks in advance

Aucun commentaire:

Enregistrer un commentaire