zoukankan      html  css  js  c++  java
  • 数据库触发器应用场景

    一、实施复杂的安全性检查

    create or replace trigger mytrigger 
    before insert
    on emp
    begin
       if to_char(sysdate,'day') in ('星期六','星期日')
          or
             to_number(to_char(sysdate,'hh24')) not between 9 and 18
       then 
       raise_application_error(-20001,'禁止插入新的员工');
      
       end if;
    end;
    /
    

    二、数据的确认

    create or replace trigger checksal 
    before update
    on emp
    for each row
    begin
       if :new.sal < :old.sal 
       then 
       raise_application_error(-20002,'涨薪后的薪水不能低于原来的薪水,涨薪后薪水:'||:new.sal||' 原来薪水:'||:old.sal);
      
       end if;
    end;
    /
    

    三、数据库基于值的审计

    --创建表保存审计后的数据
    create table empinfo(
           info varchar2(300)
    )
    --创建触发器
    create or replace trigger audits
    after update 
    on emp
    for each row
    begin
        if :new.sal > 6000 then 
           insert into empinfo values(:new.empno||'  '||:new.ename||'  '||:new.sal);
        end if;
    end;
    /
    

    四、数据的备份

    --直接创建emp表的备份表emp_back
    
    create table emp_back as select * from emp;
    
    
    create or replace trigger sync_sal
    after update 
    on emp
    for each row
    begin
       update emp_back set sal = :new.sal where empno = :new.empno; 
    end;
    /
    

    --慕课网学习小结

  • 相关阅读:
    asp.net 中input radio checked 无效
    AD对象DirectoryEntry本地开发
    Linux部署
    spring 定时任务配置使用
    闲言碎语
    javascript 折后保留一位小数
    JSON 实力应用
    水晶报表(crystal report )中显示CheckBox
    html 笔记
    转载-js按回车键实现登陆-myself
  • 原文地址:https://www.cnblogs.com/dylq/p/9878968.html
Copyright © 2011-2022 走看看