zoukankan      html  css  js  c++  java
  • 触发器

    1: 触发器的原理:在执行增删改某表之前或之后,自动执行sql语句!

    2:触发触发器时,内存中自动临时生成2个表:表名为:old:new:该表的列和操作的表完全一样!

    修改stu表  sid  sname   sage

    :old   修改之前的数据;修改之前的数据

    :new  更改之后的值;修改之后的数据

    删除stu表  sid  sname   sage

    :old   修改之前的数据;删除之前的数据

    :new  更改之后的值;删除之后的数据   空

    添加stu表  sid  sname   sage

    :old   修改之前的数据;空

    :new  更改之后的值;添加之后的数据   

    create or replace trigger t1 after update on ka for each row

    declare a varchar(50);b number;

    begin

      

      if(:new.kmoney>:old.kmoney)

        then

           a := '存钱';

           b := :new.kmoney-:old.kmoney;

      else

           a := '取钱';

           b := :old.kmoney-:new.kmoney;

       end if;

       

      insert into  liushui values(l_seq.nextval,:old.knum,a,b);

    end;

    触发器:

    前置触发,后置触发,语句触发!

    前置触发:

    create or replace trigger t1 before update on emp

    begin

         sql

    end;

    Create or replace trigger t1

    Before update on stu

    Begin

    If(to_char(sysdate,’hh24’)<9  or  to_char(sysdate,’hh24’)>18 ) then

    Raise_application_error(-20001,’老子现在不上班!不能操作stu表!’);

    End if;

    End;

    后置触发:

    Create or replace trigger t1

    After  update on stu

    Begin

    dbms_output.put_line(“我知道你修改了stu表!”);

    End;

    语句触发:

    :old   没有修改之前的数据;

    :new  更改之后的值;

    create or replace trigger t1 before update on emp for each row

    begin

          if(:old.e_price>:new.e_price) then

               raise_application_error(-20001,'xxxxxxxxxxxx');

          end if;

    end;

  • 相关阅读:
    window.location.href的用法
    echarts折线图阴影设置
    SVN使用教程图文教程
    jksj算法训练营-第二课02 时间复杂度和空间复杂度分析
    jkjj算法训练营笔记-第二课01 训练环境配置、编码技巧和code style
    MySQL 基础模块的面试题总结
    MySQL 事务的面试题总结
    MySQL 中锁的面试题总结
    MySQL 命令和内置函数
    MySQL 性能优化 & 分布式
  • 原文地址:https://www.cnblogs.com/wangchao422/p/9562900.html
Copyright © 2011-2022 走看看