首页 文章

表正在变异

提问于
浏览
0

插入此代码后,我收到错误消息

ORA-04091:表(模式).EMPLOYEES正在变异,触发器/函数可能看不到它

ORA-06512:第7行“HR.TRGADDEMP_1215034”

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;

1 回答

  • 1

    你应该插入一个正确的代码而不是这个:)

    ORA-4091 表示您的触发器尝试从中选择数据's own table. Just don' t . 决不 . 行级触发器不允许这样做 .

    此代码尝试选择您已有的数据 .

    当你有 :new.first_name:new.last_name 时,为什么要尝试选择 first_namelast_name ?等等...

相关问题