Home > Database > Oracle > How to set Oracle scheduled task to be executed every hour

How to set Oracle scheduled task to be executed every hour

下次还敢
Release: 2024-04-18 16:00:26
Original
705 people have browsed it

How to set Oracle scheduled tasks to be executed every hour? Log in to the Oracle database. Create a database package that contains the tasks to be performed. Create a scheduled task and specify it to repeat every hour. Create a job and assign it to a scheduled task. Just enable the job.

How to set Oracle scheduled task to be executed every hour

How to set Oracle scheduled tasks to be executed once every hour

To set Oracle scheduled tasks to be executed once every hour, please Perform the following steps:

1. Log in to the Oracle database

Use the correct username and password to connect to your Oracle database.

2. Create a database package

Create a new PL/SQL package that contains the tasks to be performed. For example:

<code class="sql">CREATE OR REPLACE PACKAGE BODY hourly_job AS
  PROCEDURE run_job IS
    BEGIN
      -- 在此添加要执行的任务代码
      DBMS_OUTPUT.PUT_LINE('任务已执行');
    END;
END hourly_job;</code>
Copy after login

3. Create a scheduled task

Use the DBMS_SCHEDULER package to create a scheduled task. For example:

<code class="sql">BEGIN
  DBMS_SCHEDULER.CREATE_SCHEDULE(
    schedule_name => 'hourly_schedule',
    start_date => SYSDATE,
    repeat_interval => 'FREQ=HOURLY',
    enabled => TRUE
  );
END;</code>
Copy after login

4. Create a job and assign it to the scheduled task

Use the DBMS_JOB package to create a job and assign it to the scheduled task you created . For example:

<code class="sql">BEGIN
  DBMS_JOB.SUBMIT(
    job_name => 'hourly_task',
    schedule_name => 'hourly_schedule',
    job_type => 'STORED_PROCEDURE',
    executable_name => 'hourly_job.run_job'
  );
END;</code>
Copy after login

5. Enable the job

Use the DBMS_JOB package to enable the job so that it executes immediately when the scheduled time is reached. For example:

<code class="sql">BEGIN
  DBMS_JOB.ENABLE('hourly_task');
END;</code>
Copy after login

By following these steps, you will successfully set up an Oracle cron task to execute every hour.

The above is the detailed content of How to set Oracle scheduled task to be executed every hour. 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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template