Search notes:

Oracle: DBMS_SCHEDULER - CREATE_JOB

dbms_scheduler.create_job creates a job.
create_job is overloaded so that it accommodates for different scenarios:

Create a job which runs once

create table tq84_dbms_scheduler_job_t (
   tmstamp    date,
   text       varchar2(20)
);


create or replace package tq84_dbms_scheduler_job_p as

    procedure j;
    
end tq84_dbms_scheduler_job_p;
/

create or replace package body tq84_dbms_scheduler_job_p as

    procedure j is begin

        insert into tq84_dbms_scheduler_job_t values (sysdate, 'j started');
        dbms_session.sleep(3);
        insert into tq84_dbms_scheduler_job_t values (sysdate, 'j stopped');

        commit;
    end j;

end tq84_dbms_scheduler_job_p;
/


begin

   dbms_scheduler.create_job (
      job_name         => 'TheNameOfTheJob',
      job_type         => 'STORED_PROCEDURE',
      job_action       => 'tq84_dbms_scheduler_job_p.j',
      start_date       =>  null,
      repeat_interval  =>  null,  -- Run once
      enabled          =>  true
   );

end;
/

select 
   *
from 
   user_scheduler_jobs
where
   program_name = 'TheNameOfTheJob';
  

select * from tq84_dbms_scheduler_job_t order by tmstamp;

exec dbms_session.sleep(5);

select 
   *
from 
   user_scheduler_jobs
where
   program_name = 'TheNameOfTheJob';

select * from tq84_dbms_scheduler_job_t order by tmstamp;

drop package tq84_dbms_scheduler_job_p;
drop table   tq84_dbms_scheduler_job_t;

select
   jrd.job_name,
   jrd.log_date,
   jrd.status,
   jrd.additional_info,
   jrd.actual_start_date,
   jrd.errors
from
   sys.dba_scheduler_job_run_details jrd
where
   jrd.job_name = 'THENAMEOFTHEJOB'
order by
   jrd.log_date desc
;

Create a job twice

declare

  procedure go(text in varchar2) is begin -- {

      dbms_output.put_line(text || ', trying to create job.');
      
      dbms_scheduler.create_job (
        job_name             => 'TheNameOfTheJob',
        job_type             => 'PLSQL_BLOCK',
        job_action           => 'begin dbms_lock.sleep(5); end;',
        start_date           =>  null,
        repeat_interval      =>  null,
        enabled              =>  true
      );

      dbms_output.put_line(text || ', job created');

  exception when others then

      if sqlcode = -27477 then

         dbms_output.put_line(text || ', job was started before previous ended');

      end if;

  end go; -- }

begin


  go('first');
  go('second');
  dbms_lock.sleep(7);
  go('third');

end;
/
Github repository Oracle-Patterns, path: /Installed/dbms/scheduler/create_job_twice.plsql

See also

dbms_scheduler.create_jobs creates multiple jobs in a single transaction.
dbms_scheduler

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758199680, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/databases/Oracle/installed/packages/dbms/scheduler/api/job/create/index(174): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78