新建过程和JOb的脚本

create or replace procedure Pro_cal_cltx is
  -----------------------------------------
  -- Author  : wang  chaoqun
  -- Created : 2010-9-25 18:38:03
  -- Purpose : 用来预计算车辆通行表,每小时执行一次,每天晚上多索引进行(分钟、小时、天、月表)

  --修改人:
  --修改内容:
  --修改时间:
  -----------------------------------------
  v_day       date;
  v_yesterday date;
begin
  ---参数初始化
  select to_date(to_char(sysdate, 'yyyymmdd'), 'yyyymmdd'),
         to_date(to_char(sysdate - 1, 'yyyymmdd'), 'yyyymmdd')
    into v_day, v_yesterday
    from dual;

  if to_char(sysdate, 'HH24') = '01' then
    ---分钟表
    delete from traffic_min where tjsj >= v_yesterday;
 
    insert into traffic_min nologging
      select to_date(to_char(jgsj, 'yyyy-MM-dd HH24:') ||
                     to_char(floor(to_number(to_char(jgsj, 'MI')) / 5) * 5),
                     'yyyy-MM-dd HH24:mi'),
             road,
             fxbh,
             cdh,
             round(sum(clsd) / count(1), 1),
             count(1) ll,
             1,
             0,
             0
        from cltx
       where jgsj >= v_yesterday
       group by to_char(jgsj, 'yyyy-MM-dd HH24:') ||
                to_char(floor(to_number(to_char(jgsj, 'MI')) / 5) * 5),
                road,
                fxbh,
                cdh;
    ---小时表
    delete from traffic_hour where tjsj >= v_yesterday;
 
    insert into traffic_hour nologging
      select to_date(to_char(jgsj, 'yyyy-MM-dd HH24'), 'yyyy-MM-dd HH24'),
             road,
             fxbh,
             cdh,
             round(sum(clsd) / count(1), 1),
             count(1) ll,
             1,
             0,
             0
        from cltx
       where jgsj >= v_yesterday
       group by to_char(jgsj, 'yyyy-MM-dd HH24'), road, fxbh, cdh;
    ---天表
    delete from traffic_day where tjsj >= v_yesterday;
 
    insert into traffic_day nologging
      select to_date(to_char(jgsj, 'yyyy-MM-dd'), 'yyyy-MM-dd'),
             road,
             fxbh,
             cdh,
             round(sum(clsd) / count(1), 1),
             count(1) ll,
             1,
             0,
             0
        from cltx
       where jgsj >= v_yesterday
       group by to_char(jgsj, 'yyyy-MM-dd'), road, fxbh, cdh;
    ---月表
    delete from traffic_month
     where tjsj >=
           to_date(to_char(add_months(v_day, -1), 'yyyy-MM') || '-01',
                   'yyyy-MM-dd');
 
    insert into traffic_month nologging
      select to_date(to_char(tjsj, 'yyyy-MM') || '-01', 'yyyy-MM-dd'),
             road,
             fxbh,
             cdh,
             round(sum(clsd) / count(1), 1),
             count(1) ll,
             1,
             0,
             0
        from traffic_day
       where tjsj >=
             to_date(to_char(add_months(v_day, -1), 'yyyy-MM') || '-01',
                     'yyyy-MM-dd')
       group by to_date(to_char(tjsj, 'yyyy-MM') || '-01', 'yyyy-MM-dd'),road, fxbh, cdh;
    ----索引重建
    -----------------
  else
    ---分钟表
    delete from traffic_min where tjsj >= v_day;
 
    insert into traffic_min nologging
      select to_date(to_char(jgsj, 'yyyy-MM-dd HH24:') ||
                     to_char(floor(to_number(to_char(jgsj, 'MI')) / 5) * 5),
                     'yyyy-MM-dd HH24:mi'),
             road,
             fxbh,
             cdh,
             round(sum(clsd) / count(1), 1),
             count(1) ll,
             1,
             0,
             0
        from cltx
       where jgsj >= v_day
       group by to_char(jgsj, 'yyyy-MM-dd HH24:') ||
                to_char(floor(to_number(to_char(jgsj, 'MI')) / 5) * 5),
                road,
                fxbh,
                cdh;
    ---小时表
    delete from traffic_hour where tjsj >= v_yesterday;
 
    insert into traffic_hour nologging
      select to_date(to_char(jgsj, 'yyyy-MM-dd HH24'), 'yyyy-MM-dd HH24'),
             road,
             fxbh,
             cdh,
             round(sum(clsd) / count(1), 1),
             count(1) ll,
             1,
             0,
             0
        from cltx
       where jgsj >= v_day
       group by to_char(jgsj, 'yyyy-MM-dd HH24'), road, fxbh, cdh;
    ---天表
    delete from traffic_day where tjsj >= v_yesterday;
 
    insert into traffic_day nologging
      select to_date(to_char(jgsj, 'yyyy-MM-dd'), 'yyyy-MM-dd'),
             road,
             fxbh,
             cdh,
             round(sum(clsd) / count(1), 1),
             count(1) ll,
             1,
             0,
             0
        from cltx
       where jgsj >= v_yesterday
       group by to_char(jgsj, 'yyyy-MM-dd'), road, fxbh, cdh;
    ---月表
    delete from traffic_month
     where tjsj >=
           to_date(to_char(v_day, 'yyyy-MM') || '-01', 'yyyy-MM-dd');
 
    insert into traffic_month nologging
      select to_date(to_char(tjsj, 'yyyy-MM') || '-01', 'yyyy-MM-dd'),
             road,
             fxbh,
             cdh,
             round(sum(clsd) / count(1), 1),
             count(1) ll,
             1,
             0,
             0
        from traffic_day
       where tjsj >=
             to_date(to_char(v_day, 'yyyy-MM') || '-01', 'yyyy-MM-dd')
       group by to_date(to_char(tjsj, 'yyyy-MM') || '-01', 'yyyy-MM-dd'),road, fxbh, cdh;
  end if;

  commit;
end Pro_cal_cltx;
/


DECLARE

  X NUMBER;

BEGIN

  SYS.DBMS_JOB.SUBMIT(job => X,
                     
                      what => 'begin

Pro_cal_cltx;

end;',
                     
                      next_date => to_date('16-11-2010 10:30:29',
                                           'dd-mm-yyyy hh24:mi:ss'),
                      interval  => 'sysdate+1/24');

  SYS.DBMS_OUTPUT.PUT_LINE('Job Number is: ' || to_char(x));
  commit;
END;

/

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/17179887/viewspace-678192/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/17179887/viewspace-678192/

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值