I want to create an Oracle DBMS Job that runs every week day (not on weekends) from 09:00 to 20:00 every 10 min. I wonder if I can do that in the FREQ
parameter of the job definition or I have to create a New Maintenance Window
.
It seems that with the solution proposed, the job runs at 9 and 20 only, and after first execution, when I run this query
select owner, job_name, next_run_date
from dba_scheduler_jobs
where JOB_NAME = 'GET_INVOICES_JOB';
I got 09/10/17 20:01:27,000000000 EUROPE/MADRID
'freq=minutely; interval=10; byhour=9,20; byday=MON,TUE,WED,THU,FRI; exclude=Company_Holidays; bysetpos=-1'
You may use this:
begin
dbms_scheduler.create_job (
job_name => 'jb_en_lopes',
job_type => 'STORED_PROCEDURE',
job_action => 'pr_en_lopes',
start_date => '09-oct-2017 09:00:00 am',
repeat_interval => 'freq=minutely; interval=10; byhour=9,10,11,12,13,14,15,16,17,18,19,20; byday=MON,TUE,WED,THU,FRI;',
enabled => true);
end;
When this scheduler in charge I get the results below :
select *
from dba_scheduler_job_log l
where l.job_name = 'JB_EN_LOPES'
order by l.log_date desc;
LOG_ID LOG_DATE OPERATION STATUS
1051594 10-OCT-17 09.59.01.197420 AM +03:00 RUN SUCCEEDED
1051592 10-OCT-17 09.58.02.229724 AM +03:00 RUN SUCCEEDED
1051590 10-OCT-17 09.57.03.177907 AM +03:00 RUN SUCCEEDED
1051588 10-OCT-17 09.56.01.197341 AM +03:00 RUN SUCCEEDED
Where :
select owner, job_name, next_run_date
from dba_scheduler_jobs
where JOB_NAME = 'JB_EN_LOPES';
OWNER JOB_NAME NEXT_RUN_DATE
myschema JB_EN_LOPES 10-OCT-17 08.00.00.194958 PM +03:00
I don't think this is possible:
Here are some repeat_interval examples that demonstrate the versatility and flexibility of the calendaring syntax:
Run at 10:00 pm daily from Monday to Friday:
FREQ=DAILY; BYDAY=MON,TUE,WED,THU,FRI; BYHOUR=22; BYMINUTE=0; BYSECOND=0;
Run every hour:
FREQ=HOURLY;INTERVAL=1;
Run every 5 minutes:
FREQ=MINUTELY;INTERVAL=5;
Run every Friday at 9:00 am (All three examples are equivalent):
FREQ=DAILY; BYDAY=FRI; BYHOUR=9; BYMINUTE=0; BYSECOND=0;
FREQ=WEEKLY; BYDAY=FRI; BYHOUR=9; BYMINUTE=0; BYSECOND=0;
FREQ=YEARLY; BYDAY=FRI; BYHOUR=9; BYMINUTE=0; BYSECOND=0;
Run every other Friday:
FREQ=WEEKLY; INTERVAL=2; BYDAY=FRI;
Run on Monday of weeks 5, 10 and 15 every year:
FREQ=YEARLY; BYWEEKNO=5,10,15; BYDAY=MON
Run on the last day of every month.
FREQ=MONTHLY; BYMONTHDAY=-1;
Run on the next to last day of every month:
FREQ=MONTHLY; BYMONTHDAY=-2;
Run on March 10th (Both examples are equivalent):
FREQ=YEARLY; BYMONTH=MAR; BYMONTHDAY=10;
FREQ=YEARLY; BYDATE=0310;
Run every January 10, 11, 12, 13 and 14 (Both examples are equivalent):
FREQ=YEARLY; BYDATE=0110,0111,0112,0113,0114
FREQ=YEARLY; BYDATE=0110+SPAN:5D;
Run every 10 days:
FREQ=DAILY; INTERVAL=10;
Run daily at 4:15, 5:15, and 6:15PM:
FREQ=DAILY; BYHOUR=16,17,18; BYMINUTE=15; BYSECOND=0;
Run on the 15th day of every other month:
FREQ=MONTHLY; INTERVAL=2; BYMONTHDAY=15;
Run on the 29th day of every month:
FREQ=MONTHLY; BYMONTHDAY=29;
Run on the second Wednesday of each month:
FREQ=MONTHLY; BYDAY=2WED;
Run on the last Friday of the year:
FREQ=YEARLY; BYDAY=-1FRI;
Run every 50 hours:
FREQ=HOURLY; INTERVAL=50;
Run on the last day of every other month:
FREQ=MONTHLY; INTERVAL=2; BYMONTHDAY=-1;
Run hourly for the first three days of every month:
FREQ=HOURLY; BYMONTHDAY=1,2,3;
Run on the 60th, 120th and 180th days of the year:
FREQ=YEARLY; BYYEARDAY=60,120,180;
Run on the last workday of every month (assuming that workdays are Monday through Friday):
FREQ=MONTHLY; BYDAY=MON,TUE,WED,THU,FRI; BYSETPOS=-1
Here are some more complex examples which reference the following named schedules:
BEGIN
sys.DBMS_SCHEDULER.create_schedule (
schedule_name => 'COMPANY_HOLIDAYS',
repeat_interval => 'FREQ=YEARLY; BYDATE=0704,0905,1124,1125,1225;');
sys.DBMS_SCHEDULER.create_schedule (
schedule_name => 'JUL4',
repeat_interval => 'FREQ=YEARLY; BYMONTH=JUL; BYMONTHDAY=4;');
sys.DBMS_SCHEDULER.create_schedule (
schedule_name => 'MEM',
repeat_interval => 'FREQ=YEARLY; BYMONTH=MAY; BYMONTHDAY=30;');
sys.DBMS_SCHEDULER.create_schedule (
schedule_name => 'LAB',
repeat_interval => 'FREQ=YEARLY; BYMONTH=SEP; BYMONTHDAY=5;');
sys.DBMS_SCHEDULER.create_schedule (
schedule_name => 'LAST_SAT',
repeat_interval => 'FREQ=MONTHLY; BYDAY=SAT; BYSETPOS=-1;');
sys.DBMS_SCHEDULER.create_schedule (
schedule_name => 'END_QTR',
repeat_interval => 'FREQ=YEARLY; BYDATE=0331,0630,0930,1231;');
sys.DBMS_SCHEDULER.create_schedule (
schedule_name => 'FISCAL_YEAR',
repeat_interval => 'FREQ=YEARLY;BYDATE=0301,0601,0901,1201;PERIODS=4;');
END;
/
Run on the last workday of every month, excluding company holidays:
FREQ=MONTHLY; BYDAY=MON,TUE,WED,THU,FRI; EXCLUDE=COMPANY_HOLIDAYS; BYSETPOS=-1
Run at noon every Friday and on company holidays:
FREQ=YEARLY; BYDAY=FRI;BYHOUR=12; INCLUDE=COMPANY_HOLIDAYS
Run on these three holidays: July 4th, Memorial Day, and Labor Day:
JUL4,MEM,LAB
Run on the last day of the month that is either a Saturday or last day of a quarter:
FREQ=MONTHLY; BYMONTHDAY=-1; INTERSECT=LAST_SAT,END_QTR
Run on the last Wednesday of every quarter of the fiscal year:
FREQ=FISCAL_YEAR;BYDAY=-1WED
Run on the last work day of the 2nd and 4th quarters of the fiscal year (assuming that workdays are Monday through Friday):
FREQ=FISCAL_YEAR;BYDAY=MON,TUE,WED,THU,FRI;BYPERIOD=2,4;BYSETPOS=-1