after i insert this code, i got an error telling that
ORA-04091: table (schema).EMPLOYEES is mutating, trigger/function may not see it
ORA-06512: at "HR.TRGADDEMP_1215034", line 7
ORA-04088: error during execution of trigger 'HR.TRGADDEMP_1215034'
What should i do?
CREATE OR REPLACE TRIGGER TrgAddEmp_1215034
AFTER INSERT ON Employees
FOR EACH ROW
DECLARE
v_name varchar2(35);
v_managerName varchar2(20);
v_dept varchar2(35);
BEGIN
Select first_name||' '||last_name
INTO v_name
FROM Employees where employee_id = :new.employee_id;
Select last_name
into v_managerName
from employees where employee_id = :new.manager_id;
Select department_name
into v_dept
from departments where department_id = :new.department_id;
IF v_managerName is NULL THEN
DBMS_OUTPUT.PUT_LINE('There is a new employee '|| v_name );
DBMS_OUTPUT.PUT_LINE('The supervisor for this employee has not been decided');
DBMS_OUTPUT.PUT_LINE('This employee is assigned to '||v_dept|| 'Department');
ELSIF v_dept is NULL THEN
DBMS_OUTPUT.PUT_LINE('There is a new employee '|| v_name );
DBMS_OUTPUT.PUT_LINE('This employee is supervised by ' || v_managerName);
DBMS_OUTPUT.PUT_LINE('The department for this employee has not been decided');
ELSE
DBMS_OUTPUT.PUT_LINE('There is a new employee '|| v_name );
DBMS_OUTPUT.PUT_LINE('This employee is supervised by ' || v_managerName);
DBMS_OUTPUT.PUT_LINE('This employee is assigned to '||v_dept|| 'Department');
END IF;
END;
AFTER INSERT ON Employeeswith `before INSERT ON Employees' - Moudiz