heting

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  40 随笔 :: 9 文章 :: 45 评论 :: 0 Trackbacks
--创建job
begin
  sys.dbms_job.submit(job 
=> :job,
                      what 
=> 'begin  
pr_del_log;
end;
',
                      next_date 
=> to_date('03-05-2010 08:00:00''dd-mm-yyyy hh24:mi:ss'),
                      interval 
=> 'trunc(add_months(sysdate,10),''mm'')+7/3');
  
commit;
end;
/


--创建存储过程

CREATE OR REPLACE PROCEDURE PR_DEL_LOG IS
  tables_num  
number(3);
  tables_name 
varchar2(30);
BEGIN
  
select count(*)
    
into tables_num
    
from user_tables
   
where table_name = 'LOG_20090707';
  
if tables_num > 0 then
    tables_name :
= 'LOG' || '_' || to_char(sysdate, 'yyyymm');
  
else
    tables_name :
= 'LOG_20090707';
  
end if;
  
execute immediate 'CREATE table '||tables_name||' as select * from t_sys_log where log_time < add_months(sysdate, -10)';
  
delete from t_sys_log where log_time < add_months(sysdate, -10);
  
commit;
EXCEPTION
  
WHEN OTHERS THEN
    dbms_output.put_line(
'err:' || sqlerrm);
    
rollback;
END;
posted on 2009-07-07 14:53 贺挺 阅读(857) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: