Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to run a JOB in the oracle only once a month, on the first day of the month

I wrote the process, and I would like it to be performed only once a month (on the first day of the month). Here is my code, but it is necessary to adjust the job start interval. And I can not understand how to enter the first day of the month. Also I want to do a similar job but to run it only on the 25th of each month. I will be grateful for your help!

begin
  dbms_scheduler.create_job (
     job_name           =>  'My_Job',
     job_type           =>  'STORED_PROCEDURE',
     job_action         =>  'Ins_Test2',
     start_date         =>  systimestamp, 
     repeat_interval    =>  'freq=minutely; interval = 20; byday=MON,TUE,WED,THU,FRI;',
     enabled            =>  true,
     comments           => 'My new job'
  );
end;

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Set the interval to

repeat_interval    =>  'FREQ=MONTHLY;BYMONTHDAY=25'

To evaluate the calendar expression, use DBMS_SCHEDULER.EVALUATE_CALENDAR_STRING. Example:

DECLARE
start_date        TIMESTAMP WITH time zone;
return_date_after TIMESTAMP WITH time zone;
next_run_date     TIMESTAMP WITH time zone;
BEGIN
-- start date of schedule
start_date :=
  to_timestamp_tz('CST 12:00 05-MAY-2012','TZR HH24:MI DD-MON-RRRR');
return_date_after := start_date;
FOR i IN 1..5 LOOP
  DBMS_SCHEDULER.EVALUATE_CALENDAR_STRING(  
    'FREQ=MONTHLY;BYMONTHDAY=25',
    start_date, return_date_after, next_run_date);
DBMS_OUTPUT.PUT_LINE('next_run_date: ' || next_run_date at time zone 'PST');
return_date_after := next_run_date;
END LOOP;
END;
/

next_run_date: 25-MAY-12 10.00.00.000000000 AM
next_run_date: 25-JUN-12 10.00.00.000000000 AM
next_run_date: 25-JUL-12 10.00.00.000000000 AM
next_run_date: 25-AUG-12 10.00.00.000000000 AM
next_run_date: 25-SEP-12 10.00.00.000000000 AM

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading