title: Unknown error during execution of trigger
body: <p>I've got an insert/update trigger set up which prevents an employee from existing in two tables at the same time. It works fine with catching illegal insertions/updates but i'm also getting another error report when testing the trigger with illegal insertions/updates.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>CREATE OR REPLACE TRIGGER check_foobar
  BEFORE INSERT OR UPDATE OF VarX ON FOOBAR
  FOR EACH ROW
  DECLARE
      counter NUMBER(38);
  BEGIN  
      SELECT count(*)
      INTO counter
      FROM BARFOO
      WHERE VarX = :NEW.VarX
      GROUP BY VarX;
  
  IF counter &gt; 0 THEN 
      RAISE_APPLICATION_ERROR(-20001, 'This is an illegal insertion/update');
      END IF;
  
  EXCEPTION WHEN NO_DATA_FOUND THEN DBMS_OUTPUT.PUT_LINE('TEST');
  
  END;
  /
  </code></pre>
  
  <p>And the errors ORA-06512 and ORA-04088 i'm not sure of:</p>
  
  <pre><code>SQL&gt; INSERT INTO DRIVER VALUES(2,  10345, 'AVAILABLE');
  
  Error starting at line : 26 File @test.sql
  In command -
  INSERT INTO FOOBAR VALUES(2)
  Error report -
  ORA-20001: This is an illegal insertion/update
  ORA-06512: at "HR.CHECK_FOOBAR", line 11
  ORA-04088: error during execution of trigger 'HR.CHECK_FOOBAR'
  </code></pre>
  
  <p>When i add an exception handler for the select statement my trigger stops working properly and the illegal insertion isn't prevented. But the execution error is prevented.</p>
  
  <p>UPDATE: I've added a group by and an exception to the trigger, so now the trigger still works with an exception handler but the errors ORA-06512 and ORA-04088 are still coming up with the illegal insertion/update.</p>
  
  <p>Line 11 mentioned in the error is </p>
  
  <pre><code>GROUP BY VarX;
  </code></pre>
  
  <p>Any advice would be much appreciated.</p>