title: Function in trigger - table is mutating error
body: <p>I'm supposed to do a trigger that doesn't allow updating or inserting in the row 'salary' value higher that 30% of average salary for the position(calculated by function). If the value is higher, then the trigger sets up exactly the value (average*130%).
  Function to calculate average (it's in a packet - packet1):</p>
  
  <pre><code>FUNCTION AVG_SALARY(POSITION POSITIONS.NAME%TYPE)RETURN NUMBER IS 
      AVRG NUMBER;
  BEGIN
      SELECT AVG(S.SALARY) INTO AVRG
      FROM STAFF S, POSITIONS P
      WHERE S.ID_POSITION=P.ID_POSITION AND P.NAME=POSITION
      GROUP BY P.NAME;
  END;
  </code></pre>
  
  <p>Trigger:</p>
  
  <pre><code>CREATE OR REPLACE TRIGGER TRIGGER1
  BEFORE UPDATE OF SALARY
  OR INSERT 
  ON STAFF
  FOR EACH ROW
  DECLARE
      POS POSITIONS.NAME%TYPE;
      AVRG2 NUMBER;
  BEGIN
      SELECT NAME INTO POS
      FROM POSITIONS
      WHERE ID_POSITION= :NEW.ID_POSITION ;
      AVRG2 := PACKET1.AVG_SALARY(POS);
      IF :NEW.SALARY &gt; AVRG2*1.3 THEN
          :NEW.SALARY := AVRG2*1.3;
      END IF;
  END;
  </code></pre>
  
  <p>I get the error that the table is mutating, trigger/function may not see it.
  Please, help</p>