使用DBMS_SCHEDULER定时执行任务

使用DBMS_SCHEDULER定时执行任务

The DBMS_JOB package has been superseded by the DBMS_SCHEDULER package.

create job
BEGIN
  DBMS_SCHEDULER.CREATE_JOB(job_name      
=>   ' delete_goods_job ' ,
                            job_type      
=>   ' STORED_PROCEDURE ' ,
                            job_action    
=>   ' delete_goods ' ,
                            repeat_interval 
=>   ' FREQ=SECONDLY; INTERVAL=6 ' ,
                            enabled       
=>  true,
                            comments      
=>   ' delete goods data '                   
                            );
END ;
/
drop job
BEGIN
    DBMS_SCHEDULER.DROP_JOB(job_name 
=>   ' delete_goods_job ' ); 
END ;
/
disable job
BEGIN
    DBMS_SCHEDULER.DISABLE(name 
=>   ' delete_goods_job ' ); 
END ;
/
enable job
BEGIN
    DBMS_SCHEDULER.ENABLE(name 
=>   ' delete_goods_job ' ); 
END ;
/
select jobs
select   *   from  USER_SCHEDULER_JOBS;
query logs(感谢itpub的teddyboy)
select   *   from  ALL_SCHEDULER_JOB_RUN_DETAILS
where  owner  =   ' SCOTT '
order   by  log_date  desc
delete logs
delete   from  ALL_SCHEDULER_JOB_RUN_DETAILS
where  owner  =   ' SCOTT '

参考:
1. PL/SQL Packages and Types Reference
2. http://www.itpub.net/378320.html

你可能感兴趣的:(使用DBMS_SCHEDULER定时执行任务)