How to manage jobs in Oracle)

Source: Internet
Author: User
Tags oracle documentation

In Oracle databases, the tools used to execute scheduled tasks are generally dbms_job packages. This package is easy to use and has a long history and is still widely used. Frankly speaking, this package's functionality satisfies the scheduling task running needs of most applications, so the vitality is so strong.

However, let's talk about its shortcomings here.

(Miki xiyou @ mikixiyou document: original link:
Http://mikixiyou.iteye.com/blog/1559145)

In dbms_job usage, we need to know the execution time of each job to determine the execution time of the stored procedure called by the job. Here you will say that this can also be implemented in the stored procedure. In the stored procedure, add a timestamp before and after the execution to the log table.

Yes. We used to do this when dealing with such requirements.

But since Oracle 10.1, Oracle has developed a new package DBMS_Scheduler. This package is so complicated that I didn't use it again after my first study. The feature is so powerful that we don't need much of it.

Let's see how DBMS_Scheduler solves this problem.

In sqlplus, use dbms_scheduler.create_job to create a scheduled task for scheduling a stored procedure.

The storage process is simple. I created this test to insert data into a table.

 

Create Table T1 as select sysdate as AA from dual;

Create or replace procedure sp_test_t1

Begin

Insert into T1 selectd sysdate from dual;

Commit;

End;

This stored procedure does not have input/output parameters, so it is convenient for job calling. If there are parameters in the actual running process, we will write a stored procedure to encapsulate it and then put it into the job for calling.

For example:

Create procedure gather_gtja_stats

As

Begin

SYS. dbms_stats.gather_schema_stats (ownname => 'gtja ', estimate_percent => 30, method_opt =>' for all indexed columns size auto', cascade => true, Options => 'gather ');

End;

Use dbms_scheduler.create_job to create a job. Call the Stored Procedure sp_test_t1. The execution interval is 2 minutes. The job_name name can be defined by yourself. This removes the disadvantage that the job number in dbms_job cannot be customized.

Exec dbms_scheduler.create_job (job_name => 'job _ sp_test_t1 ', job_type => 'stored _ procedure', job_action => 'SP _ test_t1 ', start_date => sysdate, repeat_interval => 'freq = minutely; interval = 2 ');

After the command is successfully executed, you can view the job configuration value in * _ scheduler_jobs.

Select * From dba_scheduler_jobs;

Select * From user_scheduler_jobs where job_name = 'job _ sp_test_t1 ';

By default, jobs created using this command are not executed. You need to change the job status to the executable status.

Exec dbms_scheduler.enable (name => 'job _ sp_test_t1 ');

You can delete and recreate it.

Exec dbms_scheduler.drop_job (job_name => 'job _ sp_test_t1 ');

Exec dbms_scheduler.create_job (job_name => 'job _ sp_test_t1 ', job_type => 'stored _ procedure', job_action => 'SP _ test_t1 ', start_date => to_date ('2017-06-12 15:30:00 ', 'yyyy-MM-DD hh24: MI: ss'), repeat_interval => 'freq = daily ');

This creation process is actually not much different from creating a job in dbms_job, but there are too many configurable tasks in DBMS_Scheduler. The execution interval is very flexible. I will not detail it here. For details, please refer to the official Oracle documentation.

DBMS_Scheduler records the execution time of each job. Therefore, you can query the execution time of each job.

For more information, see * _ scheduler_job_log and * _ scheduler_job_run_details.

Select * From dba_scheduler_job_log;

Select * From dba_scheduler_job_run_details;

If there are too many logs, you can use purge_log to clear them.

Execute dbms_scheduler.purge_log;

This DBMS_Scheduler package has too many functions and is also exhausting to use, so many people still choose dbms_job.

See the Introduction of the differences between the two packages in the http://stackoverflow.com, extract them and keep them for reference.

Original: http://stackoverflow.com/questions/8505799/job-vs-scheduler-oracle-10g

At first glance it looks like only other names with more human readable schedulesdbms_scheduler, Compareddbms_job. When looking slightly better, there are loads of differences, even in Oracle 10gr1. Currently we are in
11gr2. Every releasedbms_schedulerGets more enhancements, wheredbms_jobHas been static for policyears.

Differences

  • Dbms_sched1_has Logging
  • Dbms_sched1_has external jobs
  • Dbms_sched1_has job chains
  • DBMS_Scheduler has job event handling (can raise and react upon events)
  • Dbms_sched1_hasresource managerIntegration
  • Dbms_sched1_has human readable calendar syntax
  • DBMS_Scheduler can combine different calendars in a new one

In 11g extra

  • Dbms_sched1_has Remote external jobs
  • DBMS_Scheduler has light weight jobs-generate tables low overhead jobs in one TX
  • DBMS_Scheduler can send mail on job completion
  • Dbms_sched1_jobs can have multiple targets

Dbms_job can only run PL/SQL type of jobs in the current database.

I hope this (in complete list) h

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.