oracle 存储过程

create or replace procedure p_log_builder
as
  cursor c_abs is
  select t.bh,t.cgqdate cgqdate,t.createdat,tt.title,tt.cgqdate cgqdate1 from comm_tempcgqdate t inner join comm_sbwdbjcsgl tt
  on f_getbh(t.bh) = tt.bdzid
  and to_number(t.cgqdate)>to_number(tt.cgqdate)
  and tt.title = '绝对值告警' ;
 
  cursor c_dif is
    select ttt.*,tttt.title from                                                                                                                                                     
  (select tt.*                                                                                                                                                      
  from                                                                                                                                                              
      (                                                                                                                                                             
      select max(to_number(cgqdate)) as maxtemp,min(to_number(cgqdate)) as mintemp,t.limit_temp,t.name1,bdzid,min(t.createdat) as createdat                         
      from                                                                                                                                                          
        (                                                                                                                                                           
        select t.id,t.bh,t.name,t.bdzid,tt.id id1,tt.bh bh1,tt.cgqdate,ttt.cgqdate as limit_temp,substr(t.name,0,length(t.name)-1) name1,tt.createdat from sys_cgq t 
        inner join comm_tempcgqdate tt                                                                                                                              
        on t.bh=tt.bh                                                                                                                                               
        left join comm_sbwdbjcsgl ttt on t.bdzid = ttt.bdzid and title = '差值告警'                                                                                 
        )t                                                                                                                                                          
        group by t.name1,t.limit_temp,bdzid)tt                                                                                                                      
  where tt.maxtemp-mintemp>=limit_temp)ttt                                                                                                                          
  inner join comm_sbwdbjcsgl tttt on tttt.bdzid = ttt.bdzid and tttt.title='差值告警'  ;
begin
    for r in c_abs
    loop
        begin
          insert into sys_log_absolute(bh,cgqdate,createdat,title,cgqdate1) values(r.bh,r.cgqdate,r.createdat,r.title,r.cgqdate1);
          commit;
        EXCEPTION
        WHEN OTHERS THEN
          null;
        end;
    end loop; 
   
    for r in c_dif
    loop
         begin
              insert into SYS_LOG_DIFFERENCE(
                maxtemp,
                mintemp,
                limit_temp,
                name1,
                bdzid,
                createdat,
                title
                )
              values(
                 r.maxtemp,
                 r.mintemp,
                 r.limit_temp,
                 r.name1,
                 r.bdzid,
                 r.createdat,
                 r.title
              );
              commit;
          EXCEPTION
          WHEN OTHERS THEN
            null;
          end;
    end loop; 
   
end;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值