为了账号安全,请及时绑定邮箱和手机立即绑定

Oracle触发器

  • create or replace trigger trg

    before/after

    delete/insert/update(of 列)

    on table

    for each row(where 条件) --行级触发器 触发语句作用的每一条记录都被触发。 使用:old和:new伪记录变量,识别值的状态。

    plsql块

    查看全部
  • create or replace trigger securityemp

    before insert

    on emp

    declare

    begin

     if to_char(sysdate,'day')in('星期六','星期日')or

      to_number(to_char(sysdate,'hh24'))not between 9 and 18 then

        raise_application_error(-20001,'禁止在非工作时间')             --自定义错误代码2w到2w0999;

    end;

    /


    查看全部
  • /** *复杂的安全性检查:非工作时间禁止插入员工 */ create or replace trigger security_check before insert on emp declare 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 raise_check before update on emp for each row begin if :old.sal > :new.sal then raise_application_error(-20002,'涨工资后应该大于涨前'); end if; end; / /** *数据库的审计:记录涨工资超过6000的员工 */ create table audit_info(msg varchar2(200)); create or replace trigger over6000 after update on emp for each row begin if :new.sal > 6000 then insert into audit_info(msg) values(:new.empno || ' ' || :new.ename || ' 涨前: '|| :old.sal ||' 涨后: ' || :new.sal); end if; end; / /** * 数据的备份和同步 */ create table emp_bak as select * from emp; create or replace trigger emp_backup after update on emp for each row begin update emp_bak set sal= :new.sal where empno = :new.empno; end; /
    查看全部
  • :old 表示操作该行之前这一行的值 :new 表示操作该行之后这一行的值 create or replace trigger check_salary before update on emp for each row begin if :new.sal<:odl.sal then raise_application_error(-20002,'涨后薪水不能少于涨前薪水。 涨后薪水为:'||:new.sal ||'涨前的薪水:'||:old.sal); end if; end;
    查看全部
  • 触发器具体应用场景: 1.复杂的安全性的场景(涉及到权限的问题); 2.数据的确认(涉及数据是否合理问题); 3.数据的审计(涉及到数据的增、删、改的操作记录); 4.数据的备份和同步(备份和同步重要); 例子: 1.下班时间不能插入数据库; 2.涨工资越涨越高,低了就不能修改; 3.把操作的时间、帐户等信息记录下来; 4.不同的数据表间进行同步备份 语法: create trigger trigger_name after/before insert/delete/update on 关联表名 declare begin 逻辑... end;
    查看全部
  • 1.触发器的应用场景 复杂的安全性检查 数据的确认(数据是否合理) 数据库的审计(对数据库进行操作的记录) 数据的备份与同步(备份和同步,主从数据库数据的一致性)
    查看全部
  • 触发器应用场景四: 数据的备份和同步 例子:当给员工涨完工资后,自动备份新的工资资料到备份表中 create or replace trigger trigger_sync_salary after update on emp for each row begin update emp_back set sal=:new.sal where empno=:new.empbo; end;
    查看全部
  • 触发器应用场景三: 数据的审计---》基于值得审计功能 例子:给员工涨工资,当涨后的薪水超过6000块时候,审计该员工的信息 创建表,用于保存审计信息 create table audit_info( information varchar2(200) ); create or replace trigger do_audit_emp_salary after update on emp for each row begin if :new.sal>6000 then insert into audit_info values(:new.empno||' '||:new.ename||' '||:new.sal); end if; end;
    查看全部
  • Rff
    查看全部
  • 触发器具体应用场景: 1.复杂的安全性的场景(涉及到权限的问题); 2.数据的确认(涉及数据是否合理问题); 3.数据的审计(涉及到数据的增、删、改的操作记录); 4.数据的备份和同步(备份和同步重要);
    查看全部
  • 数据的备份和同步
    查看全部
  • 审计功能
    查看全部
  • 数据的确认
    查看全部
  • 触发器 安全性检查
    查看全部
  • 触发器应用场景四: 数据的备份和同步
    查看全部

举报

0/150
提交
取消
课程须知
学习本门课程前,需要掌握PL/SQL语法。对PL/SQL语法不了解的小伙伴请移步课程《Oracle数据库开发必备利器之PL/SQL基础》。
老师告诉你能学到什么?
1、掌握触发器的概念和语法 2、通过案例的学习,能够独立编写触发器

微信扫码,参与3人拼团

意见反馈 帮助中心 APP下载
官方微信
友情提示:

您好,此课程属于迁移课程,您已购买该课程,无需重复购买,感谢您对慕课网的支持!