The use of Oracle job in the detailed ____oracle

Source: Internet
Author: User
Tags what parameter

We often have complex business logic in project development. By using Oracle's stored procedures, you can significantly reduce the amount of Java program code written and stored procedures executed on the database, so that you can leverage Oracle's good performance support to greatly improve program execution efficiency and stability. A job is used when a stored procedure is executed regularly.

The following are the commonly used parameter descriptions:

field (column) type description
Unique identifier of the job number task
Log_user VARCHAR2 (30) the user who submitted the task
Priv_user VARCHAR2 (30) Users assigned permissions to the task
Schema_user VARCHAR2 (30) User mode for parsing a task
Last_date date the last time the task was successfully run
Last_sec VARCHAR2 (8) such as HH24:MM:SS format last_date date hours, minutes, and seconds
This_date date is running the start time of the task, or null if the task is not running
This_sec VARCHAR2 (8) such as HH24:MM:SS format this_date date hours, minutes, and seconds
Next_date date the next time the task is scheduled to run
Next_sec VARCHAR2 (8) such as HH24:MM:SS format next_date date hours, minutes, and seconds
Total_time number The total time required for the task to run, in seconds
Broken VARCHAR2 (1) flag parameter, y indicates that the task is interrupted and will not run later
INTERVAL VARCHAR2 (200) An expression used to calculate the next run time
Failures number task runs continuously without success
WHAT VARCHAR2 (2000) Pl/sql block to perform a task
Current_session_label RAW MLSLABEL Trusted Oracle Session character for this task
Clearance_hi RAW MLSLABEL Oracle maximum gap that the task can trust
Clearance_lo RAW MLSLABEL Oracle minimum gap that the task can trust
Nls_env VARCHAR2 (2000) The NLS session settings that the task runs
Some other session parameters that the Misc_env RAW (32) task runs


Describe interval parameter values
Every night 12 o'clock ' TRUNC (sysdate + 1) '
Daily 8:30 A.M. ' TRUNC (sysdate + 1) + (8*60+30)/(24*60)
Every Tuesday noon 12 o'clock ' Next_day (TRUNC (sysdate), ' Tuesday ') + 12/24 '
12 O'Clock ' TRUNC (Last_day (sysdate) + 1) ' At midnight on the first day of the month
Each quarter on the last day of the evening 11 o'clock ' TRUNC (add_months (sysdate + 2/24, 3), ' Q ') -1/24 '
Every Saturday and 6:10 A.M. ' TRUNC (Next_day (sysdate, ' SATURDAY '), Next_day (Sysdate, "SUNDAY"))) + (6X60+10)/(24x60) '

first, set initialization parameters job_queue_processes
Sql> alter system set job_queue_processes=n; (n>0)
Job_queue_processes Maximum value is 1000
  
View the job queue background process
Sql>select name,description from V$bgprocess;
  
   Two, Dbms_job package usage Introduction
Contains the following child procedures:
  
Broken () process.
The change () procedure.
Interval () process.
Isubmit () process.
Next_date () process.
The Remove () procedure.
The Run () procedure.
Submit () process.
User_export () process.
What () process.
  
1. The broken () process updates the status of a submitted work, typically used to mark a broken job as not broken.
This process has three parameters: job, broken, and next_date.
  
PROCEDURE broken (Job in Binary_integer,
Broken in Boolean,
Next_date in Date: =sysdate)
  
The job parameter is the work number, which uniquely identifies the work in the issue.
The broken parameter indicates whether this work will be marked as broken--true indicates that the work will be marked as broken, and Flase indicates that the work will be marked as not broken. Bitscn.com
The Next_date parameter indicates when this work will run again. The default value for this parameter is the current date and time.
If the job fails for some reason, Oracle will retry the execution 16 times, and it will be marked as a job with a broken reboot status of broken, as in the next two ways;
A, use Dbms_job.run () to execute the job immediately
Sql>begin
Sql>dbms_job.run (: jobno) The job number returned by the Jobno when submitting the submit process
sql>end;
sql>/
B, use Dbms_job.broken () to mark broken again as false
Sql>begin
Sql>dbms_job.broken (: job,false,next_date)
sql>end;
sql>/
2. The change () process is used to alter the settings of the specified work.
This process has four parameters: job, what, next_date, and interval.
  
PROCEDURE change (Job in Binary_integer,
What in Varchar2,
Next_date in Date,
Interval in varchar2)
  
This job parameter is an integer value that uniquely identifies the job.
The What parameter is a block of Pl/sql code that runs from this work.
The Next_date parameter indicates when this work will be performed.
The interval parameter indicates how often a work is executed. China. Network Management Alliance
  
3. The Interval () procedure is used to explicitly set the number of time intervals between the redo of a work. This process has two parameters: Job and interval.
  
PROCEDURE Interval (Job in Binary_integer,
Interval in VARCHAR2)
  
The job parameter identifies a specific job. The interval parameter indicates how often a work is executed.
  
4. The Isubmit () process is used to submit a job with a specific work number. This process has five parameters: job, what, next_date, interval, and No_parse.
  
PROCEDURE isubmit (Job in Binary_ineger,
What in Varchar2,
Next_date in Date,
Interval in varchar2,
No_parse in Booean:=false)
  
The only difference between this process and the submit () procedure is that the job parameter is passed as an in parameter and includes a work number provided by the developer. If the supplied work number is already in use, an error is generated.
  
5. The next_date () process is used to explicitly set the execution time of a job. This process receives two parameters: Job and Next_date.
  
PROCEDURE next_date (Job in Binary_ineger,
Next_date in date) bitscn.com
Job identifies a work that already exists. The Next_date parameter indicates the date and time this work should be performed.
  
6. Remove () process to delete a scheduled operation. This procedure receives an argument:
  
PROCEDURE Remove (Job in Binary_ineger);
  
The job parameter uniquely identifies a job. The value of this parameter is the value of the job parameter that is returned by calling the Submit () procedure for this work. The work that is already running cannot be deleted by the calling program.
  
7. The Run () process is used to perform a specified task immediately. This procedure receives only one parameter:
  
PROCEDURE Run (Job in Binary_ineger)
  
The job parameter identifies the work that will be executed immediately.
  
8, the use of the submit () process, the work is normally planned well.
This process has five parameters: job, what, next_date, interval, and No_parse.
  
PROCEDURE Submit (Job out Binary_ineger,
What in Varchar2,
Next_date in Date,
Interval in varchar2,
No_parse in Booean:=false)
  
The job 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.

China. Network Management Alliance


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.
  
9. The User_export () procedure returns a command that is used to schedule an existing work so that the work can be resubmitted.
This program has two parameters: Job and My_call.
  
PROCEDURE user_export (Job in Binary_ineger,
My_call in Out VARCHAR2)
  
The job parameter identifies an arranged work. The My_call parameter contains the body text required to resubmit this work in its current state.
  
10. The What () process promises to reset this running command when work is performed. This process receives two parameters: job and what.
  
PROCEDURE What (Job in Binary_ineger,
What in Out VARCHAR2)
The job parameter identifies a work that exists. The What parameter indicates the new PL/SQL code that will be executed.
  
  Third, view related job information
1. Related view
Dba_jobs
All_jobs
User_jobs
Dba_jobs_running contains information about running job

Www_bitscn_com


  
2, view the relevant information
  
Sql>select JOB, Next_date, next_sec, failures, broken
Sql>from Dba_jobs;
  
JOB next_date next_sec Failures B
------- --------- -------- -------- -
9125 01-jun-01 00:00:00 4 N
14144 24-oct-01 16:35:35 0 N
9127 01-jun-01 00:00:00 Y
3 Rows selected.
  
Running job-related information
  
SELECT SID, R.job, Log_user, R.this_date, r.this_sec
From Dba_jobs_running R, Dba_jobs J
WHERE r.job = j.job;
  
SID JOB log_user this_date this_sec
----- ---------- ------------- --------- --------
14144 HR 24-oct-94 17:21:24
8536 QS 24-oct-94 16:45:12
2 rows selected.
   
JOB QUEUE Lock Related information
  
SELECT SID, TYPE, ID1, ID2
From V$lock
WHERE TYPE = ' JQ ';
  
SID TY ID1 ID2
--------- -- --------- ---------
JQ 0 14144
1 row selected.
  
   Iv. Simple Examples
A simple example: China Network Management Alliance
  
To create a test table
Sql> CREATE TABLE TEST (a date);
  
Table has been created.
  
Create a custom procedure
sql> Create or replace procedure MYPROC as
2 begin
3 INSERT into TEST values (sysdate);
4 End;
5/
  
Procedure has been created.
  
Create Job
sql> variable JOB1 number;
Sql>
Sql> begin
2 Dbms_job.submit (: Job1, ' MYPROC; ', sysdate, ' sysdate+1/1440 '); --1440 minutes a day, that is, a minute to run the test process once
3 END;
4/
  
The PL/SQL process has completed successfully.
  
Run Job
Sql> begin
2 Dbms_job.run (: JOB1);
3 END;
4/
  
The PL/SQL process has completed successfully.
  
Sql> Select To_char (A, ' yyyy/mm/dd hh24:mi:ss ') time from TEST;
  
Time
-------------------
2001/01/07 23:51:21
2001/01/07 23:52:22
2001/01/07 23:53:24
  
Delete Job
Sql> begin
2 Dbms_job.remove (: JOB1);
3 END;
4/bitscn_com
  
The PL/SQL process has completed successfully.

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.