Oracle job details

Source: Internet
Author: User
Tags what parameter

1. Set the initialization parameter job_queue_processes.
SQL> alter system setjob_queue_processes = N; (n> 0)
Job_queue_processes: the maximum value is 1000.
  
View the Job Queue background process
SQL> select name, description fromv $ 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.    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 Forum bbs.bitscn.com
  
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) 54ne.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 Forum bbs.bitscn.com
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.

  
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
1. A simple example:

  
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/
The PL/SQL process is successfully completed.

 

   2. An example of a job executed at on the first day:

 

       

                Declare
                      X number;
                Begin
                      SYS. dbms_job.submit
                      (Job => X
                            , What => 'syn _ rpt_members_relation ;'
                            , Next_date => to_date ('02-07-200801: 00: 00', 'dd/mm/yyyy hh24: MI: ss ')
                            , Interval => 'trunc (sysdate + 1) + (1/24 )'
                            , No_parse => false
                      );
                              SYS. dbms_output.put_line ('job number is: '| to_char (x ));
                            Commit;
                End;
              /The preceding statement explicitly specifies that the job is executed at every day. If you specify to execute interval at every day, you must specify it as 'trunc (sysdate) + 1 + 123 ', if you only specify interval as one day, the daily execution time of a job changes when you manually run the job once with dbms_job.run (job, if you want to execute a job at a fixed time every day, refer to the above example. description interval parameter value:         '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'
          Every Saturday and 06:10 am 'trunc (least (next_day (sysdate, ''saturday "), next_day (sysdate,           "Sunday") + (6 × 60 + 10)/(24 × 60 )'   

      

1: executed per minute

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

Or

Interval = & gt; sysdate + 1/1440

2: daily scheduled execution

Example: Execute at every day

Interval => trunc (sysdate) + 1 + 1/(24)

3: scheduled weekly execution

Example: Execute at every Monday

Interval => trunc (next_day (sysdate, 'monday') + 1/24

4: scheduled monthly execution

Example: Execute at on the first day of every month

Interval => trunc (last_day (sysdate) + 1 + 1/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_months (sysdate, 3), 'q') + 1/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) + 1/24

7: scheduled execution every year

Example: Execute at on January 1, January 1 every year.

Interval => add_months (trunc (sysdate, 'yyyy'), 12) + 1/24

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.