How to create scheduled tasks in Oracle database: DBMS_SCHEDULER package: create jobs and programs, associate programs with jobs, and schedule jobs. Job Scheduler: Create and manage scheduled tasks using a graphical interface. DBMS_JOB package: Create a job, specify the program to run, and schedule the job.
How to create an Oracle database scheduled task
Oracle database provides a variety of methods to create scheduled tasks, including DBMS_SCHEDULER package, job scheduler, and dbms_job package.
DBMS_SCHEDULER package
The DBMS_SCHEDULER package provides a program interface for creating scheduled schedules. To create a cron job using this package, follow these steps:
<code class="sql">BEGIN DBMS_SCHEDULER.CREATE_JOB(job_name => 'my_job', job_type => 'SCHEDULED_JOB'); END; /</code>
<code class="sql">CREATE OR REPLACE PROCEDURE my_procedure AS BEGIN -- 你的代码 END; /</code>
<code class="sql">BEGIN DBMS_SCHEDULER.SET_JOB_ACTION(job_name => 'my_job', subprogram_name => 'my_procedure'); END; /</code>
<code class="sql">BEGIN DBMS_SCHEDULER.SCHEDULE_JOB(job_name => 'my_job', next_date => to_date('2023-03-08', 'yyyy-mm-dd'), repeat_interval => 'FREQ=DAILY'); END; /</code>
Job Scheduler
Job Scheduler is a graphical user interface (GUI) tool that can be used to create and manage scheduled tasks. To create a cron job using the job scheduler, follow these steps:
DBMS_JOB package
The DBMS_JOB package provides another program interface for creating scheduled schedules. To create a cron job using this package, follow these steps:
<code class="sql">BEGIN DBMS_JOB.SUBMIT(job => my_job, next_date => to_date('2023-03-08', 'yyyy-mm-dd'), interval => 'FREQ=DAILY', what => 'my_procedure'); END; /</code>
The above is the detailed content of How to create oracle database scheduled tasks. For more information, please follow other related articles on the PHP Chinese website!