一个循环的例子(loop)

来源:互联网 发布:三国志13卡顿优化补丁 编辑:程序博客网 时间:2024/05/21 22:28

这个例子对于一些技术高手来说是一个很简单的例子,但我觉得对于一个技术人员,不是拿过来一个问题就马上写出来,而是在以前的例子中有没有相关的例子,这样可以节省时间,可以把时间放到一些新的问题,这样进步会更快。下面把例子分享给大家。

-- 宽带新增用户
-- truncate table scb_lan_stat_d ;
declare
start_date date;
end_date   date;
start_in   number;
end_in     number;
vs_date    varchar2(8);
begin
start_date := to_date('20100601','yyyymmdd');
end_date   := to_date('20100831','yyyymmdd');
loop
vs_date    := to_char(start_date,'yyyymmdd');
exit when (start_date > end_date);
execute immediate '
insert into scb_lan_stat_d
(
   stat_date,
   area_code,
   new_user
)
select '
   ||vs_date||',
   substr(std_tml_id,1,2),
   count(distinct serv_id)
  from ods.tp_serv_day_'||vs_date||
' where prd_complete_in = 1
    and std_prd_id like ''1303%''
  group by substr(std_tml_id,1,2)  '
;
commit;
start_date := start_date + 1;
end loop;
end;

-- 这个例子对日累计,提一些累计数据很好。

原创粉丝点击