Summary of Oracle Database timer Job writing at various times

Source: Internet
Author: User

InOracle DatabaseWe often useTimer JobTo automatically execute scripts, back up databases, refine data, or optimize database performance, including re-indexing. However, the processing of Oracle timer Job time is ever-changing and flexible. This article summarizes the writing of some Oracle Database timer jobs in various time periods. Next we will introduce these.

Before summing up, let's take a look at the Job parameters:

The Job parameter is the binary_integer returned by the Submit () process.

What parameter is the PL/SQL code block to be executed.

The next_date parameter indicates when the job will be run. You can leave this value unspecified when writing a Job.

The interval parameter indicates when the job will be re-executed.

The Interval value is the key to determining when a Job is re-executed.

For example, a stored procedure p_dosomethings needs to be executed at different intervals.

 
 
  1. Declare
  2.  
  3. Jobno number;
  4.  
  5. Begin
  6.  
  7. Dbms_job.submit (
  8.  
  9. Jobno,
  10.  
  11. 'P _ dosomething ', -- what
  12.  
  13. To_date (), -- next_date, optional
  14.  
  15. 'Interval time string' -- Interval, key settings
  16.  
  17. );
  18.  
  19. Commit;
  20.  
  21. End;

1. Execution per minute

Interval => TRUNC (sysdate, 'mi') + 1/(24*60)

2. daily scheduled execution

Example: Execute at every day

Interval => TRUNC (sysdate) + 1 + 2/(24)

3. weekly scheduled execution

Example: Execute at every Monday

Interval => TRUNC (next_day (sysdate, 2) + 2/24 -- Monday, the second day of a week

4. scheduled monthly execution

For example, the task is executed at on the first day of every month.

Interval => TRUNC (LAST_DAY (SYSDATE) + 1 + 2/24

5. Periodical execution on a quarterly basis

For example, the statement is executed at on the first day of each quarter.

Interval => TRUNC (ADD_MONTH (SYSDATE), 3), 'q') + 2/24

6. scheduled execution every six months

For example, at a.m. on January 1, July 1 and January 1, January 1

Interval => ADD_MONTHS (trunc (sysdate, 'yyyy'), 6) + 2/24

7. Regular annual execution

For example, it is executed at on January 1, January 1 every year.

Interval => ADD_MONTHS (trunc (sysdate, 'yyyy'), 12) + 2/24

This article describes how to write an Oracle timer Job in various time periods. If you want to know

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.