定制JOB的下次执行时间的关键是利用trunc()函数,使计算时间基于一个确定的时间点。
http://yangtingkun.itpub.net/post/468/12430
tstuser@HMISD> select sysdate times,
2 TO_CHAR(sysdate, 'yyyy') yyyy,
3 TO_CHAR(sysdate, 'mm') mm,
4 TO_CHAR(sysdate, 'dd') dd,
5 TO_CHAR(sysdate, 'HH24') hh,
6 TO_CHAR(sysdate, 'MI') mi
7 from dual;
TIMES YYYY MM DD HH MI
------------------- ---- -- -- -- --
2009-01-14 16:30:33 2009 01 14 16 30
举几个简单的例子:
1.每个小时整点执行的例子:
declare
v_jobno number;
begin
dbms_job.submit(v_jobno, 'null;', trunc(sysdate, 'HH24'), 'trunc(sysdate, ''HH24'') + 1/24');
commit;
end;
/
2.每个小时半点执行的例子:
declare
v_jobno number;
begin
dbms_job.submit(v_jobno, 'null;', trunc(sysdate, 'HH24') + 3/48, 'trunc(sysdate, ''HH24'') + 3/48');
commit;
end;
/
3.每半个小时执行一次的例子:
declare
v_jobno number;
begin
dbms_job.submit(v_jobno, 'null;', trunc(sysdate, 'HH24') + FLOOR(TO_NUMBER(TO_CHAR(sysdate, 'MI'))/30)/48,
'trunc(sysdate, ''HH24'') + FLOOR(TO_NUMBER(TO_CHAR(sysdate, ''MI''))/30)/48 + 1/48');
commit;
end;
/
或者
declare
v_jobno number;
begin
dbms_job.submit(v_jobno, 'null;',
trunc(sysdate, 'HH24') + (trunc(sysdate + 1/48, 'HH24') - trunc(sysdate , 'HH24'))/2,
'trunc(sysdate, ''HH24'') + (trunc(sysdate + 1/48, ''HH24'') - trunc(sysdate , ''HH24''))/2 + 1/48');
commit;
end;
/
4.每周一早上10点执行
declare
v_jobno number;
begin
dbms_job.submit(v_jobno, 'null;',
trunc(sysdate, 'd') + 8 + 10/24, 'trunc(sysdate, ''d'') + 8 + 10/24');
commit;
end;
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/8102208/viewspace-539612/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/8102208/viewspace-539612/