1.创建表T,包含一个X字段,定义为日期类型,方便后面的定时任务测试
create table t (x date)
2.创建存储过程p_insert_into_t,每次执行该存储过程都会向T表中插入一条系统当前时间
create or replace procedure p_insert_into_t
as
begin
insert into t
values (SYSDATE);
end;
3.来创建一个JOB
declare job_number number;
begin
DBMS_JOB.submit (job_number,
'P_INSERT_INTO_T;',
SYSDATE,
'sysdate+1+2/(24)');
commit;
end;
4.我们通过USER_JOBS视图查看一下创建的JOB信息
select job,
log_user,
to_char(last_date,'yyyy-mm-dd hh24:mi:ss') last_date,
to_char(next_date,'yyyy-mm-dd hh24:mi:ss') next_date,
interval,
what
from user_jobs
手工执行JOB一次,使之按照既定的时间间隔执行
execute dbms_job.run(27);
删除Job
begin
dbms_job.remove(27);
end;