Oracle Schedules
Published by : Obay Salah , November 19, 2024
Let’s assume you want to create a group of Jobs that are executed at the same time and are repeated at the same time, and their execution is completed at the same time.
In this scenario, instead of specifying the start time for executing all these Jobs and the time for repeating the execution and the time to complete all these Jobs, it is better for you to create a Scheduler using the CREATE_SCHEDULE procedure, which performs a complete scheduling. This allows you to specify the start time for execution, the time for repetition, and the time for completion of execution.
After that, a group of Jobs can participate in this schedule through referencing this schedule during the creation of the Job using the Create_Job procedure.
Where SCHEDULE_NAME is the name of the schedule.
As for the (START_DATE & END_DATE), they are used to specify the start and end time of the execution.
The variable REPEAT_INTERVAL is used to specify the time for repeating the execution, and this variable can take one of several values such as Frequency, i.e., the repetition that can take one of the following values:
- YEARLY
- MONTHLY
- WEEKLY
- DAILY
- HOURLY
- MINUTELY
- SECONDLY
Also, the INTERVAL is used to specify the repetition time.
For example, if we wanted to execute some tasks daily at the tenth hour, the REPEAT_INTERVAL variable would look like this:
REPEAT_INTERVAL=>’FREQ=DAILY; INTERVAL=>10
And if we wanted to execute some tasks every two years, the REPEAT_INTERVAL variable would look like this:
REPEAT_INTERVAL=>’FREQ=YEARLY; INTERVAL=>2
But have you noticed that until now no month, week, or day has been specified for executing these tasks that are executed every two years? All that is specified is that these tasks will be executed every two years.
However, we may need to provide more details in such cases. We will use some elements:
- BYMONTH
- BYWEEKNO
- BYYEARDAY
- BYMONTHDAY
- BYHOUR
- BYMINUTE
- BYSECOND
If we wanted, for example, to execute some tasks every two weeks on Saturday at exactly nine-thirty, the REPEAT_INTERVAL variable would look like this:
REPEAT_INTERVAL=>’FREQ=WEEKLY;INTERVAL=2;BYDAY=SAT;BYHOUR=9;BYMINUTE=30’
Let’s assume I want to execute some tasks in four specific months of each year (Jan & Apr & Jul & Oct) on the 51st day of these months.
The REPEAT_INTERVAL would look like this:
REPEAT_INTERVAL=>’FREQ=YEARLY;BYMONTH=JAN,APR,JUL,OCT;BYMONTHDAY=51
Now let’s assume we want to create a schedule to execute the tasks daily for a month.
BEGIN DBMS_SCHEDULER.CREATE_SCHEDULE( SCHEDULE_NAME=>'DIALY', START_DATE=>SYSDATE, REPEAT_INTERVAL=>'FREG=DAILY;INTERVAL=1', END_DATE=>SYSDATE+30); END;
You can inquire about the schedules in the database using the DBA_SCHEDULER_SCHEDULES view.
We can also delete these schedules using the DROP_SCHEDULER procedure.
BEGIN DBMS_SCHEDULER.DROP_SCHEDULE( SCHEDULE_NAME=>'DIALY', FORCE=>TRUE); END; /
Comments
no comment yet!