日期:2014-05-17 浏览次数:20775 次
declare
cursor my_cursor(c_tm_intrvl_cd number) is(
select to_number(to_char(sysdate,'yyyyMMddhh24')) deal_date,t.tm_intrvl_cd, t.road_cd,t.hr_cd,
round(nvl(avg(t.Road_Avg_Spd),15),2) as ROAD_AVG_SPD,
round(avg(t.Road_Avg_Time),2) as Road_Avg_Time,round(avg(t.samp_num),2) as samp_num
from zhnj_eds.DM_FCT_ROAD_AVGSPD_DAY t
where t.tm_intrvl_cd in(
to_number(to_char(to_date(c_tm_intrvl_cd,'yyyyMMddhh24'),'yyyyMMddhh24')),
to_number(to_char(to_date(c_tm_intrvl_cd,'yyyyMMddhh24')-7,'yyyyMMddhh24')),
to_number(to_char(to_date(c_tm_intrvl_cd,'yyyyMMddhh24')-7*2,'yyyyMMddhh24')),
to_number(to_char(to_date(c_tm_intrvl_cd,'yyyyMMddhh24')-7*3,'yyyyMMddhh24')))
group by road_cd,t.tm_intrvl_cd,t.hr_cd);
my_cursor_row DM_FCT_ROAD_AVGSPD_DAY%ROWTYPE;
begin
for rec_tmp in (select tm_intrvl_cd from DM_FCT_ROAD_AVGSPD_DAY group by tm_intrvl_cd order by tm_intrvl_cd)
loop
--dbms_output.put_line('时间为' || rec_tmp.tm_intrvl_cd);
open my_cursor(rec_tmp.tm_intrvl_cd);
LOOP
FETCH my_cursor INTO my_cursor_row;
EXIT WHEN my_cursor%NOTFOUND;
dbms_output.put_line('时间为' || rec_tmp.tm_intrvl_cd || my_cursor_row.ROAD_AVG_SPD);
--insert into dm_fct_road_avgspd_day_spcl values(my_cursor_row.deal_date,my_cursor_row.road_cd,my_cursor_row.tm_intrvl_cd,my_cursor_row.hr_cd,my_cursor_row.ROAD_AVG_SPD,my_cursor_row.Road_Avg_Time,my_cursor_row.samp_num);
END LOOP;
CLOSE my_cursor;
end loop;
end;
create table DM_FCT_ROAD_AVGSPD_DAY
(
DEAL_DATE NUMBER(8) not null,
ROAD_CD VARCHAR2(50),
TM_INTRVL_CD NUMBER(10),
HR_CD NUMBER(2),
ROAD_AVG_SPD NUMBER(5,2),
ROAD_AVG_TIME NUMBER(10,2),
SAMP_NUM NUMBER(5)
);