-- Add variable
Variable job1 number;
-- Create a JOB
Begin
Dbms_job.submit (: job1, 'testjob; ', sysdate, 'trunc (sysdate + 1) + 1000 ');
COMMIT;
End;
/
-- Query the corresponding JOB number
Select job, last_date, last_sec, broken, failures, interval, what from dba_jobs;
-- Run the JOB manually
Begin
Dbms_job.run (23 );
End;
/
-- Delete a JOB
Begin
Dbms_job.remove (24 );
End;
/
-- Set the task execution time
1: executed per minute
Interval => TRUNC (sysdate, 'mi') + 1/(24*60) -- executed per minute
Interval => 'sysdate + 1/(24*60) '-- executed per minute
Interval => 'sysdate + 1' -- daily
Interval => 'sysdate + 123' -- Hourly
Interval => 'sysdate + 2/24 * 60' -- every 2 minutes
Interval => 'sysdate + 30/24*60 * 60' -- every 30 seconds
2: daily scheduled execution
Interval => TRUNC (sysdate + 1) -- run at every day
Interval => TRUNC (sysdate + 1) + 1/24 -- run at every day
Interval => TRUNC (SYSDATE + 1) + (8*60 + 30)/(24*60) -- run at 08:30 every morning
3: scheduled weekly execution
Interval => TRUNC (next_day (sysdate, 'monday') + 1/24 -- run at every Monday
Interval => TRUNC (next_day (sysdate, 1) + 2/24 -- run at every Monday
4: scheduled monthly execution
Interval => TTRUNC (LAST_DAY (SYSDATE) + 1) -- executed at on the first day of each month
Interval => TRUNC (LAST_DAY (SYSDATE) + 1 + 1/24 -- executed at on the first day of each month
5: Periodical execution on a quarterly basis
Interval => TRUNC (ADD_MONTHS (SYSDATE, 3), 'q') -- executed at on the first day of each quarter
Interval => TRUNC (ADD_MONTHS (SYSDATE, 3), 'q') + 1/24 -- run at on the first day of each quarter
Interval => TRUNC (ADD_MONTHS (SYSDATE + 2/24, 3), 'q')-1/24 -- run at on the evening of the last day of each quarter
6: scheduled execution every six months
Interval => ADD_MONTHS (trunc (sysdate, 'yyyy'), 6) + 1/24 -- each year on January 1, July 1 and January 1, January 1
7: scheduled execution every year
Interval => ADD_MONTHS (trunc (sysdate, 'yyyy'), 12) + 1/24 -- executed at on January 1, January 1 every year