Home  >  Article  >  Database  >  Oracle scheduled tasks execute the creation step once a day

Oracle scheduled tasks execute the creation step once a day

下次还敢
下次还敢Original
2024-05-10 03:03:17436browse

To create a scheduled task that is executed once a day in Oracle, you need to perform the following three steps: Create a job. Add a subjob to the job and set its schedule expression to "INTERVAL 1 DAY". Enable the job.

Oracle scheduled tasks execute the creation step once a day

How to create a scheduled task that is executed once a day in Oracle

Create a scheduled task that is executed once a day in Oracle The steps of the task are as follows:

1. Create a job

<code>CREATE JOB job_name
AS
sys.dbms_scheduler.create_job(job_name,
                              'DEFAULT_JOB_CLASS',
                              'job_desc');</code>

where:

  • job_name: the name of the job
  • DEFAULT_JOB_CLASS: The default job class of the job
  • job_desc: The description of the job

2. Add a sub-job to the job

<code>sys.dbms_scheduler.create_job_subjob(job_name,
                                 'job_subname',
                                 'job_type',
                                 'job_parameters',
                                 'schedule_expression',
                                 'enabled');</code>

where :

  • job_subname: The name of the subjob
  • job_type: The type of subjob (for example, EXECUTABLE, SQL, PLSQL_BLOCK)
  • job_parameters: The parameters of the subjob ( Varies based on job_type)
  • schedule_expression: The schedule expression of the subjob (for example, 'INTERVAL 1 DAY')
  • enabled: Whether the subjob is enabled ('TRUE' or 'FALSE')

3. Enable jobs

<code>sys.dbms_scheduler.enable(job_name);</code>

Example (using SQL to execute a simple SELECT query)

<code>CREATE JOB daily_job
AS
sys.dbms_scheduler.create_job(job_name,
                              'DEFAULT_JOB_CLASS',
                              'Daily job to execute a SQL query');

sys.dbms_scheduler.create_job_subjob(job_name,
                                 'daily_subjob',
                                 'SQL',
                                 'BEGIN
                                   SELECT COUNT(*)
                                   FROM users;
                                 END;',
                                 'INTERVAL 1 DAY',
                                 'TRUE');

sys.dbms_scheduler.enable(job_name);</code>

The above is the detailed content of Oracle scheduled tasks execute the creation step once a day. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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