title: Oracle trigger after insert or delete
body: <p>Sorry for my english. </p>
  
  <p>I have 2 tables:</p>
  
  <pre><code>Table1
  id
  table2_id
  num
  modification_date 
  </code></pre>
  
  <p>and</p>
  
  <pre><code>Table2
  id
  table2num
  </code></pre>
  
  <p>I want to make a trigger which after insert or delete in <code>Table1</code> updates the last value <code>num</code> in <code>Table2.table1lastnum</code>.</p>
  
  <p>My trigger:</p>
  
  <pre><code>CREATE OR REPLACE TRIGGER TABLE1_NUM_TRG
    AFTER INSERT OR DELETE ON table1
    FOR EACH ROW
  BEGIN
    IF INSERTING then
  
    UPDATE table2
    SET    table2num = :new.num
    WHERE  table2.id = :new.table2_id;
  
    ELSE
  
    UPDATE table2
    SET    table2num = (SELECT num FROM  (SELECT num FROM table1 WHERE table2_id = :old.table2_id ORDER BY modification_date DESC) WHERE ROWNUM &lt;= 1)
    WHERE  table2.id = :old.table2_id;
  
    END IF;
  
  END TABLE1_NUM_TRG; 
  </code></pre>
  
  <p>But after delete in <code>Table1</code> I have error:</p>
  
  <pre><code>ORA-04091: table BD.TABLE1 is mutating, trigger/function may not see it
  ORA-06512: at "BD.TABLE1_NUM_TRG", line 11
  ORA-04088: error during execution of trigger 'BD.TABLE1_NUM_TRG'
  </code></pre>
  
  <p>What am I doing wrong?</p>