zoukankan      html  css  js  c++  java
  • oracle trigger pl/sql

    a sample of the trigger:

    --the occasion before running the trigger

    SQL> select * from a

      2  /

      DEPARTNO DEPARTNAME NUM(PK)

    ---------- --------------------

           100 部门一  1

           200 部门二  2

           300 部门三  3

    SQL> select * from c

      2  /

          C_NO C_NAME                      DEP

    ---------- -------------------- ----------

             1 1                           100

             2 2                           200


    --run the create trigger sentence

    create or replace trigger my_trigger after update on scott.a for each row

    begin

        update scott.c set dep=:new.departno

        where dep=:old.departno;

    end;


    Trigger created


    --trigger the constrain and the event will be executed.

    SQL> update a set departno=500 where departno=100;


    --you can refer to the following result:

    SQL> select * from a

      2  /

      DEPARTNO DEPARTNAME                  NUM

    ---------- -------------------- ----------

           500 部门一                        1

           200 部门二                        2

           300 部门三                        3

    SQL> select * from c

      2  /

          C_NO C_NAME                      DEP

    ---------- -------------------- ----------

             1 1                           500

             2 2                           200

     temp table:new and :old

     ---after insert,then we only read :new 

    create or replace trigger my_trigger after insert on a for each row

    begin

    dbms_output.put_line(:new.departno);

    end;


    ---after update,then we read both :old and :new 

    create or replace trigger my_trigger after update on a for each row

    begin

    dbms_output.put_line(:old.departno);

    dbms_output.put_line(:new.departno);

    end;


    ---after delete,then we only read :old 

    create or replace trigger my_trigger after delete on a for each row

    begin

    dbms_output.put_line(:old.departno);

    end;

     sql output --> file

    spool $path;

    spool off;

    quit; 

  • 相关阅读:
    【例题 8-11 UVA-10954】Add All
    【例题 8-10 UVA
    【BZOJ1226】学校食堂Dining(状压DP)
    【Tyvj1601】魔兽争霸(主席树,树套树)
    【BZOJ3504】危桥(最大流)
    【BZOJ1812】riv(多叉树转二叉树,树形DP)
    【Vijos1412】多人背包(背包DP)
    【Codevs1907】方格取数3(最小割)
    【Codevs1227】方格取数2(费用流)
    【Tyvj1982】武器分配(费用流)
  • 原文地址:https://www.cnblogs.com/kelin1314/p/1821090.html
Copyright © 2011-2022 走看看