Confirmation of Oracle Database Trigger Data

a need

Wages cannot be raised more or less.
 
two code
  1. --触发器应用场景2:数据的
  2. --涨后的薪水不能少于涨前的薪水
  3. /*
  4. :old和:new代表的是同一条记录
  5. :new 表示操作该行之前,这一行的值
  6. :old 表示操作该行之后,这一行的值
  7. */
  8. create or replace trigger checksalary
  9. before update
  10. on emp
  11. for each row
  12. begin
  13. if:old.sal >:new.sal then
  14. raise_application_error(-20002,'涨后的薪水不能少于涨前的薪水 涨前'||:old.sal||'涨后'||:new.sal);
  15. endif;
  16. end;
  17. /
 
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'

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326149434&siteId=291194637