Stop long running scheduled job I need to launch a scheduled job at 12 o'clock at night and keep this job running for a period of 8 hours. What happens now is that the job is running for more than 12 hours and I really need to avoid running for so long. I have used the Max Run Duration option but it does not have the desired effect for my purpose. I would appreciate if someone could give me an example of how it should be. Database is Oracle 12c. Here I put the script:

BEGIN
  SYS.DBMS_SCHEDULER.CREATE_JOB
    (
       job_name        =&gt; 'SYS.POB_TB_JOB'
      ,start_date      =&gt; TO_TIMESTAMP_TZ('2019/02/10 00:05:00.000000 America/New_York','yyyy/mm/dd hh24:mi:ss.ff tzr')
      ,repeat_interval =&gt; 'FREQ=DAILY;BYDAY=MON,TUE,WED,THU,FRI,SAT,SUN'
      ,end_date        =&gt; NULL
      ,job_class       =&gt; 'DEFAULT_JOB_CLASS'
      ,job_type        =&gt; 'STORED_PROCEDURE'
      ,job_action      =&gt; 'SELLER.FILL_TB_S1'
      ,comments        =&gt; NULL
    );

  SYS.DBMS_SCHEDULER.SET_ATTRIBUTE
    ( name      =&gt; 'SYS.POB_TB_JOB'
     ,attribute =&gt; 'MAX_RUN_DURATION'
     ,value     =&gt; TO_DSINTERVAL('+000 05:00:00'));

  SYS.DBMS_SCHEDULER.SET_ATTRIBUTE
    ( name      =&gt; 'SYS.POB_TB_JOB'
     ,attribute =&gt; 'number_of_arguments'
     ,value     =&gt; 4);

  SYS.DBMS_SCHEDULER.SET_JOB_ARGUMENT_VALUE
    ( job_name             =&gt; 'SYS.POB_TB_JOB'
     ,argument_position    =&gt; 1
     ,argument_value       =&gt; '30');

  SYS.DBMS_SCHEDULER.SET_JOB_ARGUMENT_VALUE
    ( job_name             =&gt; 'SYS.POB_TB_JOB'
     ,argument_position    =&gt; 2
     ,argument_value       =&gt; 'N');

  SYS.DBMS_SCHEDULER.SET_JOB_ARGUMENT_VALUE
    ( job_name             =&gt; 'SYS.POB_TB_JOB'
     ,argument_position    =&gt; 3
     ,argument_value       =&gt; 'N');

  SYS.DBMS_SCHEDULER.SET_JOB_ARGUMENT_VALUE
    ( job_name             =&gt; 'SYS.POB_TB_JOB'
     ,argument_position    =&gt; 4
     ,argument_value       =&gt; '1');

  SYS.DBMS_SCHEDULER.ENABLE
    (name                  =&gt; 'SYS.POB_TB_JOB');
END;
/
Attribute MAX_RUN_DURATION does not terminate the job, it only raises an event.

I created a procedure like this:

procedure SchedulerWatchdog(jobName in varchar2) is

cursor Jobs is
select job_name
from user_scheduler_jobs
where JOB_NAME = jobName
   AND STATE = 'RUNNING'
   AND systimestamp - LAST_START_DATE &gt; MAX_RUN_DURATION;

begin
   for aJob in Jobs loop
      DBMS_SCHEDULER.STOP_JOB(JobName, FORCE =&gt; TRUE);
   end loop;
end;


Run this procedure by scheduler job, perhaps every Minute.