zoukankan      html  css  js  c++  java
  • 触发器实例(二)

    create or replace trigger TR_T_DWXX
    after delete or update or insert ON T_DWXX
     for each row
    --单位 改变后 修改单位关系表
    declare
      curr_dwdh number:=0 ;
      PRAGMA AUTONOMOUS_TRANSACTION;--开启自治事物
      i number:=0;
    BEGIN
    
      if inserting then
         select t.n_sjdw into curr_dwdh from t_dwxx t where t.n_dwdh=:new.N_SJDW;
         loop -- 循环语句,找出当前节点上面还有几层节点,即分析当前节点是第几级
             exit when curr_dwdh =99999999;--根节点就退出
    
             INSERT INTO T_DWGX (N_DWDH,N_XJDW,N_GXJS)
              values (curr_dwdh,:new.N_DWDH,i);
              i:=i+1;
             select t.n_sjdw into curr_dwdh from t_dwxx t where   t.n_dwdh=curr_dwdh;
         end loop;
         INSERT INTO T_DWGX (N_DWDH,N_XJDW,N_GXJS)
          values (:new.N_SJDW,:new.N_DWDH,i);
      elsif updating then
        delete from T_DWGX where N_XJDW=:old.n_dwdh;
        select t.n_sjdw into curr_dwdh from t_dwxx t where t.n_dwdh=:new.N_SJDW;
        loop --循环语句,找出当前节点上面还有几层节点,即分析当前节点是第几级
             exit when curr_dwdh =99999999;--根节点就退出
              INSERT INTO T_DWGX (N_DWDH,N_XJDW,N_GXJS)
              values (curr_dwdh,:new.N_DWDH,i);
               i:=i+1;
             select t.n_sjdw into curr_dwdh from t_dwxx t where   t.n_dwdh=curr_dwdh;
        end loop;
        INSERT INTO T_DWGX (N_DWDH,N_XJDW,N_GXJS)
          values (:new.N_SJDW,:new.N_DWDH,i);
      elsif deleting then
         delete from T_DWGX where N_XJDW=:old.n_dwdh;
      end if;
    COMMIT;
    END;
  • 相关阅读:
    告别08
    WinForm程序如何将子窗体嵌入到父窗体的Panel里
    几种排序算法
    接口的特征
    什么是重写
    C#异常处理
    什么是重载
    结构和类的区别
    Javascript的函数
    在ASP.NET中防止注入攻击
  • 原文地址:https://www.cnblogs.com/mingyue1818/p/3327167.html
Copyright © 2011-2022 走看看