Oracle Job uses ____oracle

Source: Internet
Author: User

Steps:

(1) Create job

(2) Create job

Dbms_job.submit ();

Submit (Jobno out Binary_ineger,
What in Varchar2,
Next_date in Date,
Interval in varchar2,
No_parse in Booean:=false)
  
The Jobno parameter is the Binary_ineger returned by the submit () procedure. This value is used to uniquely identify a job.
The What parameter is the PL/SQL code block that will be executed, which is the task.
The Next_date parameter indicates when this work will be run.
Interval parameter when this work will be executed again.
The No_parse parameter indicates whether this work should be parsed at commit time or at execution--true indicates that the Pl/sql code should parse when it first executes, and False indicates that the PL/SQL code should be parsed immediately.

(3) Running

Dbms_job.run (Jobno);

(4) Delete

Dbms_job.remove (Jobno)

--Suspend a job
EXEC Dbms_job.broken (jobno,true)
Commit//must be submitted otherwise invalid
Start a job
EXEC Dbms_job.broken (jobno,false)

/*********************************************************************************/

Eg: Insert a piece of data into a table every minute through a job

Create or Replace package body test is
--Create a table
Procedure CreateTable is
Num number;
Begin
--See if the system table already exists, not created

Select COUNT (*) into the num from user_tables where table_name= ' temp_job ';
if (num>0) then
--Delete Table
Execute immediate ' drop table temp_job ';
Commit
End If;
--Create a table
Execute immediate ' CREATE TABLE Temp_job (
Address VARCHAR2 (200),
Sdate Date
)';
Commit
End CreateTable;

--Create a task to insert a record into the list
Procedure Insertrecord AS
Begin
Insert into Temp_job (address,sdate) VALUES (' MM ' | | Sysdate,sysdate);
Commit
End Insertrecord;

--Create a scheduling scheduler
Procedure Schejob is
Jobno number;
Begin
--Create a table
test.createtable;
Commit
--Create Job
Dbms_job.submit (Jobno, ' Scott.test.insertRecord; ', sysdate, ' sysdate+1/1440 ');-the user must be added. Name of the stored procedure otherwise the report must specify the identifier ' Insertrecord ' ERROR
Commit
--1440 minutes a day, that is, a minute to run the test process once
--Run job
Dbms_job.run (Jobno);
Commit
--Delete Job
--dbms_job.remove (Jobno);
End Schejob;

End test;

Run the stored procedure

Command Window window

exec scott.test.scheJob;--user name. package name. Stored Procedure Name

Results:

select * Form Temp_job;

Table Temp_job more than one record per minute.

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.