Oracle job Usage Details

Source: Internet
Author: User
Tags what parameter

In project development, we often have complicated business logic. Using the stored procedures of Oracle can greatly reduce the compilation workload of Java program code, and the stored procedures are executed on the database, so that the good performance of Oracle can be used, greatly improve program execution efficiency and stability. Scheduled execution of stored procedures requires the use of jobs.

Common parameters are described as follows:

Field (column) type description
Unique ID of a job number
Log_user varchar2 (30) user who submits the task
Priv_user varchar2 (30) user with task Permissions
Schema_user varchar2 (30) User Mode for Syntactic Analysis of tasks
Last_date date the time when the last task was successfully run
Last_sec varchar2 (8) such as hh24: mm: hour, minute, and second of the SS format last_date
The start time of the task being run by this_date. If no task is running, the value is null.
This_sec varchar2 (8) such as hh24: mm: the hour, minute, and second of the this_date date in SS format
Next_date date the next scheduled task running time
Next_sec varchar2 (8) such as hh24: mm: the hour, minute, and second of the SS format next_date
Total_time number the total time required to run the task, in seconds
The broken varchar2 (1) Flag parameter. y indicates that the task is interrupted and will not run later.
Interval varchar2 (200) is the expression used to calculate the next line time.
Failures number the number of times the task failed to run continuously
What varchar2 (2000) PL/SQL block for task execution
Current_session_label raw mlslabel trust Oracle session character of the task
Clearance_hi raw mlslabel maximum gap between Oracle databases trusted by this task
Clearance_lo raw mlslabel minimum Oracle gap trusted by this task
NLS session settings for running the nls_env varchar2 (2000) task
Other session parameters of the misc_env raw (32) task

Parameter Value of Interval
'Trunc (sysdate + 1) 'At midnight every day )'
Every morning 08:30 'trunc (sysdate + 1) + (8*60 + 30)/(24*60 )'
Next _ day (trunc (sysdate), ''tuesday'') + 12/24 at every Tuesday'
'Trunc (last_day (sysdate) + 1) 'at midnight on the first day of each month )'
'Trunc (add_months (sysdate + 2/24, 3), 'q')-100' at on the last day of each quarter'
'Trunc (least (next_day (sysdate, ''saturday "), next_day (sysdate," Sunday ") + (6 × 60 + 10) /(24 × 60 )'

 

1. Set the initialization parameter job_queue_processes.
SQL> alter system set job_queue_processes = N; (n> 0)
Job_queue_processes: the maximum value is 1000.
  
View the Job Queue background process
SQL> select name, description from V $ bgprocess;
  
  2. dbms_job package usage
It contains the following sub-processes:
  
Broken () process.
Change () process.
Interval () process.
Isubmit () process.
Next_date () process.
Remove () process.
Run () process.
Submit () process.
User_export () process.
What () process.
  
1. The broken () process updates the status of a submitted job. It is typically used to mark a broken job as a non-broken job.
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 problem.
The broken parameter indicates whether the job is marked as broken -- true indicates that the job is marked as broken, and flase indicates that the job is marked as not broken.
Bitscn. com
The next_date parameter indicates when the job will run again. The default value of this parameter is the current date and time.
If a job fails for some reason, Oracle will retry 16 times and fail to execute successfully. It will be marked as a job in broken restart status, there are two methods;
A. Use dbms_job.run () to execute the job immediately.
SQL> begin
SQL> dbms_job.run (: jobno) The jobno is the job number returned when the submit process is submitted.
SQL> end;
SQL>/
B. Use dbms_job.broken () to mark the broken as false again.
SQL> begin
SQL> dbms_job.broken (: Job, false, next_date)
SQL> end;
SQL>/
2. The change () process is used to change the settings of a specified job.
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)
  
The job parameter is an integer that uniquely identifies the job.
The what parameter is a PL/SQL code block that runs from this job.
The next_date parameter indicates when the job will be executed.
The interval parameter indicates the frequency of re-execution. China Network Management Alliance
  
3. The interval () process is used to explicitly set the time interval between re-execution of a job. 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 the frequency of re-execution.
  
4. The isubmit () process is used to submit a job with a specific job 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 () process is that this job parameter is passed as an in-type parameter and includes a work number provided by the developer. If the provided work number is used, 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
A job identifies an existing job. The next_date parameter indicates the date and time when the job should be executed.
  
6. Remove () to delete a scheduled job. This process receives a parameter:
  
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 returned when submit () is called for this job. A running job cannot be deleted by a called program.
  
7. The run () process is used to immediately execute a specified job. This process only receives one parameter:
  
Procedure run (job in binary_ineger)
  
The job that will be executed immediately.
  
8. Use the submit () process and the work is properly planned.
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 () process. This value uniquely identifies a job.
What parameter is the PL/SQL code block to be executed.

China Network Management Alliance

The next_date parameter specifies when the job will be run.
The interval parameter indicates when the job will be re-executed.
The no_parse parameter indicates whether the job should perform syntax analysis at the time of submission or execution -- true indicates that the PL/SQL code should perform syntax analysis during its first execution, false indicates that the PL/SQL code should be analyzed immediately.
  
9. A command is returned during the user_export () process. This command is used to schedule an existing job so that the job can be submitted again.
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 a scheduled job. The my_call parameter contains the body required to resubmit the job in its current state.
  
10. What () process promises to reset the running command during job execution. This process receives two parameters: job and what.
  
Procedure what (job in binary_ineger,
What in out varchar2)
The job parameter identifies an existing job. What parameter indicates the new PL/SQL code to be executed.
  
  3. View related job information
1. Related views
Dba_jobs
All_jobs
User_jobs
Dba_jobs_running contains information about running jobs.

Www_bitscn_com

  
2. View related 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--01 -01 16:35:35 0 n
9127 01-jun-01 00:00:00 16 Y
3 rows selected.
  
Information about running jobs
  
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
---------------------------------------------
12 14144 HR 24-oct-94 17:21:24
25 8536 QS 24-oct-94 16:45:12
2 rows selected.
   
Job Queue lock Information
  
Select Sid, type, id1, Id2
From v $ lock
Where type = 'jq ';
  
Sid ty id1 Id2
-----------------------------
12 JQ 0 14144
1 row selected.
  
  Iv. Simple examples
A simple example: China Network Management Alliance
  
Create test table
SQL> Create Table Test (a date );
  
The table has been created.
  
Create a custom Process
SQL> Create or replace procedure myproc
2 begin
3 insert into test values (sysdate );
4 end;
5/
  
The process has been created.
  
Create a job
SQL> variable job1 number;
SQL>
SQL> begin
2 dbms_job.submit (: job1, 'myproc; ', sysdate, 'sysdate + 100'); -- 1/1440 minutes a day, that is, one minute to run the test process
3 end;
4/
  
The PL/SQL process is successfully completed.
  
Run job
SQL> begin
2 dbms_job.run (: job1 );
3 end;
4/
  
The PL/SQL process is successfully completed.
  
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 a job
SQL> begin
2 dbms_job.remove (: job1 );
3 end;
4/bitscn_com
  
The PL/SQL process is successfully completed.

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.