a need
Wages cannot be raised more or less.
two code
--触发器应用场景2:数据的
--涨后的薪水不能少于涨前的薪水
/*
:old和:new代表的是同一条记录
:new 表示操作该行之前,这一行的值
:old 表示操作该行之后,这一行的值
*/
create or replace trigger checksalary
before update
on emp
for each row
begin
if:old.sal >:new.sal then
raise_application_error(-20002,'涨后的薪水不能少于涨前的薪水 涨前'||:old.sal||'涨后'||:new.sal);
endif;
end;
/
Three verification
SQL> update emp set sal=sal+1 where empno=7839;
1 row updated.
SQL> update emp set sal=sal-1 where empno=7839;
update emp set sal=sal-1 where empno=7839
*
Error on line 1:
ORA-20002: The salary after the increase cannot be less than the salary before the increase 10101 before the increase 10100 after the increase
ORA-06512: 在 "SCOTT.CHECKSALARY", line 3
ORA-04088: error during execution of trigger 'SCOTT.CHECKSALARY'