/*
--create test table
create table T_JOB_TEST
(
JID NUMBER(20) not null,
JDate Date,
constraint PK_T_JOB_TEST primary key(JID)
)
--create sequence
create sequence SEQ_T_JOB_TEST
minvalue 1
maxvalue 9999999999999999999999999999
start with 1
increment by 1
cache 20;
--create PROCEDURE
CREATE OR REPLACE PROCEDURE P_T_JOB_TEST(jids IN number,isSuccess OUT number,id OUT number)
IS
BEGIN
insert into T_JOB_TEST values(jids,sysdate) returning jid into id;
isSuccess := sql%rowcount;
END;
declare
iss number;
ids number;
begin
P_T_JOB_TEST(SEQ_T_JOB_TEST.Nextval,iss,ids);
dbms_output.put_line(ids||' '||iss);
end;
select * from T_JOB_TEST
*/
--create job
declare
job number;
begin
sys.dbms_job.submit(job => job,
what => 'declare
iss number;
ids number;
begin
P_T_JOB_TEST(SEQ_T_JOB_TEST.Nextval,iss,ids);
dbms_output.put_line(ids||iss||job);
end;',
next_date => to_date('2013-05-22 14:00:00', 'yyyy-mm-dd hh24:mi:ss'),
interval => 'sysdate+1/1440');
commit;
end;
SELECT * FROM USER_JOBS;
begin
DBMS_JOB.RUN(244);
end;
begin
DBMS_JOB.REMOVE(244);
end;
job时间周期:
每天运行一次 'SYSDATE + 1'
每小时运行一次 'SYSDATE + 1/24'
每10分钟运行一次 'SYSDATE + 10/(60*24)'
每30秒运行一次 'SYSDATE + 30/(60*24*60)'
每隔一星期运行一次 'SYSDATE + 7'
每天午夜12点: 'TRUNC(SYSDATE + 1)'
每天早上8点30分: 'TRUNC(SYSDATE + 1) + (8*60+30)/(24*60)'
每星期二中午12点: 'NEXT_DAY(TRUNC(SYSDATE ), ''TUESDAY'' ) + 12/24'
每个月第一天的午夜12点: 'TRUNC(LAST_DAY(SYSDATE ) + 1)'
每个季度最后一天的晚上11点: 'TRUNC(ADD_MONTHS(SYSDATE + 2/24, 3 ), 'Q' ) -1/24'
每星期六和日早上6点10分: 'TRUNC(LEAST(NEXT_DAY(SYSDATE, ''SATURDAY"), NEXT_DAY(SYSDATE, "SUNDAY"))) + (6×60+10)/(24×60)'
每月25号00:00执行: 'TRUNC(LAST_DAY(SYSDATE ) + 25)'