zoukankan      html  css  js  c++  java
  • TRIGGERS_监测系统_多表视图触发器—向原始数据报表中插入数据

    Create Or Replace Trigger trg_view_report
      Instead Of Insert or update or delete on view_for_report
      for each row
    Declare

    begin
      If Inserting Then
     
       
        if :new.temperature1 <= 250 then
            
          insert into originaldata_report
            (id,
             wid,
             wname,
             jurisdiction,
             jurisdiction_name,
             year,
             month,
             day,
             temperature,
             humidity)
          values
            (originaldata_report_id.nextval,
             :new.wid,
             :new.wname,
             1,
             '传感器一',
             :new.year,
             :new.month,
             :new.day,
             :new.temperature1,
             :new.humidity1);
          
            
        end if;
        if :new.temperature2 <= 250 then
          
          insert into originaldata_report
            (id,
             wid,
             wname,
             jurisdiction,
             jurisdiction_name,
             year,
             month,
             day,
             temperature,
             humidity)
          values
            (originaldata_report_id.nextval,
             :new.wid,
             :new.wname,
             2,
             '传感器二',
             :new.year,
             :new.month,
             :new.day,
             :new.temperature2,
             :new.humidity2);
        end if;
        if :new.temperature3 <= 250 then
          insert into originaldata_report
            (id,
             wid,
             wname,
             jurisdiction,
             jurisdiction_name,
             year,
             month,
             day,
             temperature,
             humidity)
          values
            (originaldata_report_id.nextval,
             :new.wid,
             :new.wname,
             3,
             '传感器三',
             :new.year,
             :new.month,
             :new.day,
             :new.temperature3,
             :new.humidity3);
        end if;
        if :new.temperature4 <= 250 then
          insert into originaldata_report
            (id,
             wid,
             wname,
             jurisdiction,
             jurisdiction_name,
             year,
             month,
             day,
             temperature,
             humidity)
          values
            (originaldata_report_id.nextval,
             :new.wid,
             :new.wname,
             4,
             '传感器四',
             :new.year,
             :new.month,
             :new.day,
             :new.temperature4,
             :new.humidity4);
        end if;
        if :new.temperature5 <= 250 then
          insert into originaldata_report
            (id,
             wid,
             wname,
             jurisdiction,
             jurisdiction_name,
             year,
             month,
             day,
             temperature,
             humidity)
          values
            (originaldata_report_id.nextval,
             :new.wid,
             :new.wname,
             5,
             '传感器五',
             :new.year,
             :new.month,
             :new.day,
             :new.temperature5,
             :new.humidity5);
        end if;
        if :new.temperature6 <= 250 then
          insert into originaldata_report
            (id,
             wid,
             wname,
             jurisdiction,
             jurisdiction_name,
             year,
             month,
             day,
             temperature,
             humidity)
          values
            (originaldata_report_id.nextval,
             :new.wid,
             :new.wname,
             6,
             '传感器六',
             :new.year,
             :new.month,
             :new.day,
             :new.temperature6,
             :new.humidity6);
        end if;
        if :new.temperature7 <= 250 then
          insert into originaldata_report
            (id,
             wid,
             wname,
             jurisdiction,
             jurisdiction_name,
             year,
             month,
             day,
             temperature,
             humidity)
          values
            (originaldata_report_id.nextval,
             :new.wid,
             :new.wname,
             7,
             '传感器七',
             :new.year,
             :new.month,
             :new.day,
             :new.temperature7,
             :new.humidity7);
        end if;
        if :new.temperature8 <= 250 then
          insert into originaldata_report
            (id,
             wid,
             wname,
             jurisdiction,
             jurisdiction_name,
             year,
             month,
             day,
             temperature,
             humidity)
          values
            (originaldata_report_id.nextval,
             :new.wid,
             :new.wname,
             8,
             '传感器八',
             :new.year,
             :new.month,
             :new.day,
             :new.temperature8,
             :new.humidity8);
        end if;
        if :new.temperature9 <= 250 then
          insert into originaldata_report
            (id,
             wid,
             wname,
             jurisdiction,
             jurisdiction_name,
             year,
             month,
             day,
             temperature,
             humidity)
          values
            (originaldata_report_id.nextval,
             :new.wid,
             :new.wname,
             9,
             '传感器九',
             :new.year,
             :new.month,
             :new.day,
             :new.temperature9,
             :new.humidity9);
        end if;
        if :new.temperature10 <= 250 then
          insert into originaldata_report
            (id,
             wid,
             wname,
             jurisdiction,
             jurisdiction_name,
             year,
             month,
             day,
             temperature,
             humidity)
          values
            (originaldata_report_id.nextval,
             :new.wid,
             :new.wname,
             10,
             '传感器十',
             :new.year,
             :new.month,
             :new.day,
             :new.temperature10,
             :new.humidity10);
        end if;
      elsif Deleting then
        Delete from originaldata_report t where t.wid = :Old.wid;
      End if;
    end ;

  • 相关阅读:
    【BZOJ 4581】【Usaco2016 Open】Field Reduction
    【BZOJ 4582】【Usaco2016 Open】Diamond Collector
    【BZOJ 4580】【Usaco2016 Open】248
    【BZOJ 3754】Tree之最小方差树
    【51Nod 1501】【算法马拉松 19D】石头剪刀布威力加强版
    【51Nod 1622】【算法马拉松 19C】集合对
    【51Nod 1616】【算法马拉松 19B】最小集合
    【51Nod 1674】【算法马拉松 19A】区间的价值 V2
    【BZOJ 2541】【Vijos 1366】【CTSC 2000】冰原探险
    【BZOJ 1065】【Vijos 1826】【NOI 2008】奥运物流
  • 原文地址:https://www.cnblogs.com/hy928302776/p/3233262.html
Copyright © 2011-2022 走看看