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 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>
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>
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>
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>
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!