create or replace procedure p_tfm_TGS5MVOLUM (pDate in date)
as
---------
v_reportdate date := pDate;
 cursor Cur_Dwbh is
 select t.dwbh from kklw.t_base_dljkjcxx t ;
 --------------
 v_OutTfmdwbh  kklw.t_base_dljkjcxx.dwbh%type;
 begin 
---计算时间
SELECT TRUNC(pDate , 'HH24') +
           FLOOR(TO_CHAR(pDate , 'MI') / 5) * 5 / 1440
      INTO v_reportdate
      FROM DUAL;
      ------游标查找点位编号
   open Cur_Dwbh;
 loop
   fetch Cur_Dwbh into  v_OutTfmdwbh;
   exit when Cur_Dwbh%notfound;
insert into t_tfm_detector_5m_tempsource t(DETECTORID,detectortype,detcode,datetime,volume,speed,timeopy,state)
select detectorid,
       'TGS' detectortype,
       d as DATETIME,
       cdbh as DETCODE,
       nvl(sum(cllz), 0) as VOLUME,
       '0' speed,
       '0' timeopy,
       '0' state
  from (SELECT DWBH || xsfx as detectorid,
               DWBH,
               cdbh,
               JGSJ TJCQ,
               MI,
               count(MI) cllz
          FROM (SELECT dwbh,
                       substr(to_char(JGSJ, 'yyyy-MM-dd hh24:mi:ss'), 0, 13) JGSJ,
                       xsfx,
                       cdbh,
                       floor(to_number(substr(to_char(JGSJ,
                                                      'yyyy-MM-dd hh24:mi:ss'),
                                              15,
                                              2)) / 5) * 5 MI,
                       case
                         when cwkc >= 600 then
                          0
                         else
                          1
                       end CWKC
                  FROM kklw.t_clxx
                 WHERE JGSJ >=
                       to_date(v_reportdate, 'yyyy-MM-dd hh24:mi')
                   AND jgsj <=
                       to_date(v_reportdate, 'yyyy-MM-dd hh24:mi') +
                       5 / 24 / 60) T
         WHERE 1 = 1
         GROUP BY JGSJ, MI, DWBH, xsfx, cdbh) t
 right join (select dwbh, d
               from (SELECT A.DWBH
                       FROM kklw.t_base_dljkjcxx A
                      where a.dwbh = v_OutTfmdwbh),
                    (select to_char(to_date(v_reportdate,
                                            'YYYY-MM-DD HH24:mi') +
                                    (rownum - 1) / 24 / 60 * 5,
                                    'yyyy-mm-dd hh24:mi') as d from kklw.t_clxx  where rownum <= (to_date(v_reportdate, 'YYYY-MM-DD HH24:mi') - to_date(v_reportdate, 'YYYY-MM-DD HH24:mi')) / (1 / 24 / 60 * 5) + 1)) tt
    on t.dwbh = tt.dwbh
   and t.tjcq = substr(tt.d, 0, 13)
   and to_number(t.mi) = to_number(substr(tt.d, 15, 2))
 group by detectorid, cdbh, d
 order by d 
  END LOOP;
  CLOSE Cur_Dwbh;