📄 multi_table2.txt
字号:
/*变异表:当不读取被改变的行时,是否还是变异表呢?*/create or replace trigger check_salarybefore insert or update on empfor each rowdeclare v_minsalary emp.sal%type; v_maxsalary emp.sal%type; v_sal emp.sal%type;begin --只从emp取一个值,可不可以呢? v_minsalary :=100; v_maxsalary :=2000; select sal into v_sal from emp where ename='KINGa'; if :new.sal > v_sal then raise_application_error(-20254,'more than king'); end if;end;insert into emp (empno,ename,sal) values(111,'008',6000);ERROR at line 1:ORA-20254: more than kingORA-06512: at "SCOTT.CHECK_SALARY", line 11ORA-04088: error during execution of trigger 'SCOTT.CHECK_SALARY'insert into emp (empno,ename,sal) values(111,'008',10);--没有被认为是变异表--okupdate emp set sal=100 where empno=101;ERROR at line 1:ORA-04091: table SCOTT.EMP is mutating, trigger/function may not see itORA-06512: at "SCOTT.CHECK_SALARY", line 9ORA-04088: error during execution of trigger 'SCOTT.CHECK_SALARY'--被认为是变异表!--trigger 是before insert or update 为什么不同呢?--oracle已声明:For a single row INSERT, 变异表--for AFTER row triggers,but not for BEFORE row triggers. INSERT-----------------------------------------before改为after-----------create or replace trigger check_salaryafter insert or update on empfor each rowdeclare v_minsalary emp.sal%type; v_maxsalary emp.sal%type; v_sal emp.sal%type;begin --只从emp取一个值,可不可以呢? v_minsalary :=100; v_maxsalary :=2000; select sal into v_sal from emp where ename='KINGa'; if :new.sal > v_sal then raise_application_error(-20254,'more than king'); end if;end;insert into emp (empno,ename,sal) values(113,'008',6);ERROR at line 1:ORA-04091: table SCOTT.EMP is mutating, trigger/function may not see itORA-06512: at "SCOTT.CHECK_SALARY", line 9ORA-04088: error during execution of trigger 'SCOTT.CHECK_SALARY'
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -