插入此代码后,我收到错误消息
ORA-04091:table(schema).EMPLOYEES正在变异,触发器/函数可能看不到它
ORA-06512:at" HR.TRGADDEMP_1215034",第7行
ORA-04088:执行触发器时出错' HR.TRGADDEMP_1215034'
我该怎么办?
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;
答案 0 :(得分:1)
您应该插入正确的代码而不是:)
ORA-4091
表示您的触发器尝试从其自己的表中选择数据。只是不要这样做。决不。行级触发器不允许这样做。
此代码尝试选择您已有的数据。
为什么你要选择first_name
& last_name
和:new.first_name
后:new.last_name
?等等...