Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/203.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Oracle 表正在变异_Oracle - Fatal编程技术网

Oracle 表正在变异

Oracle 表正在变异,oracle,Oracle,在我插入这段代码后,我得到了一个错误 ORA-04091:表(架构)。员工正在变异,触发器/函数可能看不到它 ORA-06512:“HR.TRGADDEMP_1215034”,第7行 ORA-04088:执行触发器“HR.TRGADDEMP_1215034”时出错 我该怎么办 CREATE OR REPLACE TRIGGER TrgAddEmp_1215034 AFTER INSERT ON Employees FOR EACH ROW DEC

在我插入这段代码后,我得到了一个错误

ORA-04091:表(架构)。员工正在变异,触发器/函数可能看不到它

ORA-06512:“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;

您应该插入正确的代码,而不是以下代码:)

ORA-4091
表示触发器试图从自己的表中选择数据。不要这样做。从不行级触发器不允许这样做

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


当您有
:new.first\u name
:new.last\u name
时,为什么要尝试选择
first\u name
:new.last\u name
?等等…

将员工插入后的
替换为“员工插入前”
不要那么严格,有一个例外:你是对的。但这个例外意味着使用单行插入,所以任何应用程序修改都可能再次导致ORA-4091。这就是为什么我更喜欢说“从不”。