create or replace procedure P_A_DAILY_HIS_EXE  is
v_currdate date; --当前日期
  v_count    integer; --已统计天数
begin
 
  v_currdate := null;
  v_count    := 0;
 
  --从统计表中,取出已经统计数据的最大日期,本次从这一天开始统计
  begin
    select to_date(max(statdate || ' 00:00:01'), 'yyyy-mm-dd hh24:mi:ss')
      into v_currdate
      from A_DAILYTJ;
  exception
    when NO_DATA_FOUND then
      v_currdate := null;
    when others then
      v_currdate := null;
  end;
 
  --如果是初次统计(统计表中没有数据),则设置从2010-07-01开始
  if v_currdate is null then
    v_currdate := to_date('2010-07-01 00:00:01', 'yyyy-mm-dd hh24:mi:ss');
  end if;
  loop
    exit when v_currdate > sysdate or v_count >= 30; --每次执行不超过30天,阈值可调整
    A_DAILY_HIS(v_currdate);
    v_currdate := v_currdate + 1;
    v_count    := v_count + 1;
  end loop; 
  
end P_A_DAILY_HIS_EXE;我想到2010年12月30日停止怎么办?

解决方案 »

  1.   


    create or replace procedure P_A_DAILY_HIS_EXE is
    v_currdate date; --当前日期
    v_count integer; --已统计天数
    begin
    if to_char(sysdate,'yyyy-mm-dd')>'2010-12-30' then
    dbms_output.put_line('return');
    return;
    end if;
    dbms_output.put_line('not execute');
    /*
    其他部分
    */
    end;
    /
      

  2.   

     loop
      exit when v_currdate > sysdate or v_count >= 30; --每次执行不超过30天,阈值可调整
      A_DAILY_HIS(v_currdate);
      v_currdate := v_currdate + 1;
      v_count := v_count + 1;
      end loop调整一下阀值,把30修改成182 就能推出了