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;
触发:
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 > AVRG2*1.3 THEN
:NEW.SALARY := AVRG2*1.3;
END IF;
END;
我得到表变异的错误,触发器/函数可能看不到它。 请帮忙