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; 

  • 相关阅读:
    Matlab高级教程_第一篇:Matlab基础知识提炼_01
    量化投资_量化投资系统框架的DIY_02_01
    计量经济与时间序列_时间序列之物理含义
    计量经济与时间序列_协整和误差修正模型
    数学之美_正态分布(Python代码)
    [转载] ./configure,make,make install的作用
    [转载]Deep Learning(深度学习)学习笔记整理
    AJAX XML 实例
    百度搜索插件源码
    apache 服务器在ubuntu上图片无法显示解决
  • 原文地址:https://www.cnblogs.com/kelin1314/p/1821090.html
Copyright © 2011-2022 走看看