oracle创建job

oracle创建job
-- 创建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 ;

你可能感兴趣的:(oracle创建job)