Oracle regularly calls stored procedures

Source: Internet
Author: User

 

-- Create a test table name

Create table job_table (run_date date );

-- Create a stored procedure

Create or replace procedure job_proc

Begin

Insert into job_table (run_date) values (sysdate );

End;

 

-- Create a job and run it once every minute

Declare

Job number;

Begin

Dbms_job.submit (job, 'job _ proc; ', sysdate, 'trunc (sysdate, ''mi'') + 1/(24*60 )');

End;

Commit;

 

 

-- Pause a task

 

-- Select job from user_jobs

Find the id value of the job and use the following statement to stop the job.

 

Begin

Dbms_job.broken (584, true );

End;

 

 

-- Restart a task

 

Begin

Dbms_job.execute (584 );

End;

-- Delete a task

Delete user_jobs where job = 584;

Drop procedure job_proc;

Drop table job_table;

 

After creating a job. The system automatically calls the stored procedure at a specified time.

 

 

Knowledge about time interval:

 

1. TRUNC (for dates)

 

The date value intercepted by the TRUNC function for the specified element.

 

The syntax format is as follows:

 

TRUNC (date [, fmt])

 

Where: date is a date value fmt date format, which is truncated by the specified Element format. Ignore it and it is intercepted by the latest date.

 

The usage of this function is as follows:

 

TRUNC (TO_DATE ('24-Nov-1999 12:00:00 pm '), 'dd-mon-yyyy hh: mi am') = '24-Nov-1999 am'

 

TRUNC (TO_DATE ('24-Nov-1999 08:00:00 pm ', 'dd-mon-yyyy hh: mi am'), 'hh') = '24-Nov-1999 am'

 

Trunc (sysdate, 'yyyy') -- returns the first day of the current year.

 

Trunc (sysdate, 'mm') -- returns the first day of the current month.

 

Trunc (sysdate, 'D') -- returns the first day of the current week.

 

Trunc (sysdate, 'dd') -- returns the current year, month, and day.

 

 

The unit of the number appended to the trunc function is day.

 

 

00:00 every morning: trunc (sysdate + 1)

 

Every morning at trunc (sysdate + 1) + 1/3

 

Trunc (sysdate + 1) + (8.5*60)/(24*60) at 08:30 every day)

 

Every morning at 08:30 trunc (sysdate + 1) + 8.5/24

 

Trunc (sysdate + 1) + (8*60 + 30)/(24*60) at 08:30 every day)

 

From Program Development Technology blog Xiao Li technology home

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.