1.官网给出时间频率的参数说明,更加详细可参考官网
http://docs.oracle.com/cd/E11882_01/appdev.112/e40758/d_sched.htm#BABFBCEF
2.实例
(1)每周5的时候运行,以下3条实现功能一样
REPEAT_INTERVAL => 'FREQ=DAILY; BYDAY=FRI';
REPEAT_INTERVAL => 'FREQ=WEEKLY; BYDAY=FRI';
REPEAT_INTERVAL => 'FREQ=YEARLY; BYDAY=FRI';
(2)每隔一周运行一次,仅在周5运行
REPEAT_INTERVAL => 'FREQ=WEEKLY; INTERVAL=2; BYDAY=FRI’;
(3)每月最后一天运行
REPEAT_INTERVAL => 'FREQ=MONTHLY; BYMONTHDAY=-1';
(4)在3月10日运行
REPEAT_INTERVAL => 'FREQ=YEARLY; BYMONTH=MAR; BYMONTHDAY=10’;
REPEAT_INTERVAL => 'FREQ=YEARLY; BYDATE=0310';
(5)每10隔天运行
REPEAT_INTERVAL => 'FREQ=DAILY; INTERVAL=10’;
(6)每天的下午4、5、6点时运行
REPEAT_INTERVAL => 'FREQ=DAILY; BYHOUR=16,17,18’;
(7)每月29日运行
REPEAT_INTERVAL => 'FREQ=MONTHLY; BYMONTHDAY=29’;
(8)每年的最后一个周5运行
REPEAT_INTERVAL => 'FREQ=YEARLY; BYDAY=-1FRI’;
(9)每隔50个小时运行
REPEAT_INTERVAL => 'FREQ=HOURLY; INTERVAL=50’;
3.查看执行时间周期,可以根据定义好的FREQ来推算出后10次的时间
脚本如下:
-
set serveroutput on size 999999
-
declare
-
L_start_date TIMESTAMP;
-
l_next_date TIMESTAMP;
-
l_return_date TIMESTAMP;
-
begin
-
l_start_date := trunc(SYSTIMESTAMP);
-
l_return_date := l_start_date;
-
for ctr in 1..10 loop
-
dbms_scheduler.evaluate_calendar_string(
-
'FREQ=YEARLY;BYHOUR=6;BYMINUTE=30;BYSECOND=0;BYDAY=-1FRI',
-
l_start_date, l_return_date, l_next_date
-
);
-
dbms_output.put_line('Next Run on: ' ||
-
to_char(l_next_date,'mm/dd/yyyy hh24:mi:ss')
-
);
-
l_return_date := l_next_date;
-
end loop;
-
end;
-
/
example: 每年的最后一个周5,6点30分运行
-
SCOTT@OCM11G >set serveroutput on size 999999
-
SCOTT@OCM11G >declare
-
2 L_start_date TIMESTAMP;
-
3 l_next_date TIMESTAMP;
-
4 l_return_date TIMESTAMP;
-
5 begin
-
6 l_start_date := trunc(SYSTIMESTAMP);
-
7 l_return_date := l_start_date;
-
8 for ctr in 1..10 loop
-
9 dbms_scheduler.evaluate_calendar_string(
-
10 'FREQ=YEARLY;BYHOUR=6;BYMINUTE=30;BYSECOND=0;BYDAY=-1FRI',
-
11 l_start_date, l_return_date, l_next_date
-
12 );
-
13 dbms_output.put_line('Next Run on: ' ||
-
14 to_char(l_next_date,'mm/dd/yyyy hh24:mi:ss')
-
15 );
-
16 l_return_date := l_next_date;
-
17 end loop;
-
18 end;
-
19 /
-
Next Run on: 12/30/2016 06:30:00
-
Next Run on: 12/29/2017 06:30:00
-
Next Run on: 12/28/2018 06:30:00
-
Next Run on: 12/27/2019 06:30:00
-
Next Run on: 12/25/2020 06:30:00
-
Next Run on: 12/31/2021 06:30:00
-
Next Run on: 12/30/2022 06:30:00
-
Next Run on: 12/29/2023 06:30:00
-
Next Run on: 12/27/2024 06:30:00
-
Next Run on: 12/26/2025 06:30:00
-
-
PL/SQL procedure successfully completed.
四、总结
通过简单的学习与实践,我对DBMS_SCHEDULER包中的CREATE_JOB过程有了基本认识。但这些还是远远不够的,面对今后的挑战,学习的脚步不能停。Where there is a will, there is a way.