?? 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 + -