实现步骤:
1.创建一个测试表
create table test(dTime date);
2.创建一个存储过程
create or replace procedure p_test as
begin
insert into test values(sysdate);
end;
3.创建执行计划:每小时运行一次存储过程
Declare
i Integer;
Begin
dbms_job.submit(i,'p_test;',Sysdate,'sysdate+1/24');
end;
4.运行执行计划
Declare
jobno Integer;
Begin
-- 查找计划号
Select t.JOB into jobno From User_Jobs t where t.JOB='45';
-- 运行制定的执行计划
dbms_job.run(jobno);
end;
5.查看任务队列情况
select job,next_date,next_sec,failures,broken from user_jobs;
6.查看任务执行情况
select to_char(dTime ,'yyyy/mm/dd hh24:mi:ss') from test order By dTime;
7.停止执行计划
Declare
jobno Integer;
Begin
-- 查找计划号
Select t.JOB into jobno From User_Jobs t where t.JOB='45';
-- 停止计划,不再继续执行
--dbms_job.broken(jobno,True);
-- 停止计划,并在两分钟后继续执行
dbms_job.broken(jobno,True,Sysdate+(2/24/60));
end;
8.删除执行计划
Declare
jobno Integer;
Begin
-- 查找计划号
Select t.JOB into jobno From User_Jobs t where t.JOB='45';
dbms_job.remove(jobno);
end;
9.修改执行计划
Declare
jobno Integer;
Begin
-- 查找计划号
Select t.JOB into jobno From User_Jobs t where t.JOB='45';
-- 修改为:每分钟执行一次
dbms_job.interval(jobno, 'sysdate+1/(24*60)');
end;