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;

  • 相关阅读:
    【刷题】BZOJ 1036 [ZJOI2008]树的统计Count
    【刷题】BZOJ 1180 [CROATIAN2009]OTOCI
    【刷题】BZOJ 1453 [Wc]Dface双面棋盘
    【刷题】BZOJ 4025 二分图
    【模考】2018.04.08 Connection
    【模考】2018.04.08 Travel
    【刷题】BZOJ 4825 [Hnoi2017]单旋
    【刷题】洛谷 P3613 睡觉困难综合征
    【刷题】BZOJ 3668 [Noi2014]起床困难综合症
    CSS3_边框 border 详解_一个 div 的阴阳图
  • 原文地址:https://www.cnblogs.com/wangchao422/p/9562900.html
Copyright © 2011-2022 走看看