Home > Database > Oracle > body text

How to create oracle database scheduled tasks

下次还敢
Release: 2024-04-19 03:24:16
Original
1108 people have browsed it

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 oracle database scheduled tasks

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:

  1. Create a job:
<code class="sql">BEGIN
  DBMS_SCHEDULER.CREATE_JOB(job_name => 'my_job', job_type => 'SCHEDULED_JOB');
END;
/</code>
Copy after login
  1. Create a program:
<code class="sql">CREATE OR REPLACE PROCEDURE my_procedure AS
BEGIN
  -- 你的代码
END;
/</code>
Copy after login
  1. Associate a program with a job:
<code class="sql">BEGIN
  DBMS_SCHEDULER.SET_JOB_ACTION(job_name => 'my_job', subprogram_name => 'my_procedure');
END;
/</code>
Copy after login
  1. Schedule a job:
<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>
Copy after login

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:

  1. Open the job scheduler (for Windows) or run dbmsched (for UNIX).
  2. Click the "New" button.
  3. Enter job name and description.
  4. Select the "Job" type from the "Stages" tab.
  5. In the "Program" tab, specify the program to run.
  6. In the "Schedule" tab, schedule the job.

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:

  1. Create a job:
<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>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!