zoukankan      html  css  js  c++  java
  • PROCEDURE_监测系统_原始数据报表数据生成存储过程—求每天平均值插入多表视图

    create or replace procedure proc_generate_report(in_date in varchar2) is
      v_retCode varchar2(20);
      v_retMsg  varchar2(500);
    begin
      v_retCode:= '';
      v_retMsg:= '';
      insert into view_for_report
      select t.id,
             max(w.wid) wid,
             max(w.wname) wname,
             substr(max(t.time), 1, 4) year,
             substr(max(t.time), 6, 2) month,
             substr(max(t.time), 9, 2) day,
             round(avg(temperature1), 2) temperature1,
             round(avg(humidity1), 2) humidity1,
             round(avg(temperature2), 2) temperature2,
             round(avg(humidity2), 2) humidity2,
             round(avg(temperature3), 2) temperature3,
             round(avg(humidity3), 2) humidity3,
             round(avg(temperature4), 2) temperature4,
             round(avg(humidity4), 2) humidity4,
             round(avg(temperature5), 2) temperature5,
             round(avg(humidity5), 2) humidity5,
             round(avg(temperature6), 2) temperature6,
             round(avg(humidity6), 2) humidity6,
             round(avg(temperature7), 2) temperature7,
             round(avg(humidity7), 2) humidity7,
             round(avg(temperature8), 2) temperature8,
             round(avg(humidity8), 2) humidity8,
             round(avg(temperature9), 2) temperature9,
             round(avg(humidity9), 2) humidity9,
             round(avg(temperature10), 2) temperature10,
             round(avg(humidity10), 2) humidity10
        from originaldata t, warehouse_new w
       where t.id = w.client_id
         and t.time <= in_date
       group by t.id;
      commit;
    exception
      when others then
        v_retCode := sqlcode;
        v_retMsg  := sqlerrm || sysdate;
        insert into operationlog
          (id, time, behavior, state, reason)
        values
          (operationlog_id_seq.nextval,
           to_char(sysdate, 'yyyy-mm-dd hh24:mi:ss'),
           '生成报表数据',
           0,
           v_retMsg);
        commit;
    end proc_generate_report;

  • 相关阅读:
    mysql 刘道成视频教程 第4-8课 --- 数据类型
    mysql 刘道成视频教程 第3课
    9款优秀的开源版本控制和源代码管理系统 转载
    mysql主要应用场景 转载
    平时收藏网页
    mysql 刘道成视频教程1、2课----------大致结构
    软件
    visual studio 2010 快捷键
    将CString(unicode)转换为char*(ANSI)
    去掉Visual Studio 编辑器里中文注释的红色波浪线 转载
  • 原文地址:https://www.cnblogs.com/hy928302776/p/3233247.html
Copyright © 2011-2022 走看看