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;

  • 相关阅读:
    Linq与Lambda,神一般的工作效率
    svn和git孰优孰劣
    关于C++的***5的输出问题
    POJ 3469 Dual Core CPU(最小割)
    HDU 4259 Double Dealing
    最大流Dinic算法
    HDU 4442 Physical Examination(2012年金华赛区现场赛A题)
    int ,long , long long类型的范围
    POJ 1679 The Unique MST(判断最小生成树是否唯一)
    HDU 4280 Island Transport(网络流)
  • 原文地址:https://www.cnblogs.com/wangchao422/p/9562900.html
Copyright © 2011-2022 走看看