Oracle uses it--configured scheduling tasks

Requirement: Managers modify the execution frequency or other parameters of scheduling tasks as needed (the frequency is demonstrated here)

Build a stored procedure to modify the schedule

CREATE OR REPLACE
PROCEDURE change_job
( p_value in VARCHAR,     --入参
  p_msg out VARCHAR) is --out parameter
BEGIN
 
dbms_job.change (
    41,
    'MOVE_DATA;',   
    SYSDATE + 5/(60*24),
    p_value
);  
 p_msg := 'The execution was successful';
 EXCEPTION  
    WHEN OTHERS  
    THEN  
      p_msg := 'Execution error';
      DBMS_OUTPUT.PUT_LINE ('Exception happened,data was rollback');  
      ROLLBACK;  
END;

mybatis call stored procedure

<select id="changeTask" statementType="CALLABLE">
	{call change_job(
	#{interval,jdbcType=VARCHAR,mode=IN},
	#{message,jdbcType=VARCHAR,mode=OUT}
	)}
</select>

In the dbms_job package there are other procedures for operating scheduling tasks:

broken、change、interval、isubmit、next_date、remove、run、submit、user_export、what;

1. The broken() procedure updates the status of a submitted job, typically used to mark a broken job as unbroken. 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 job number, which uniquely identifies the job in the question. 
The broken parameter indicates whether the job will be marked broken - true means the job will be marked broken, while false means the job will be marked unbroken. 
The next_date parameter indicates when this job will run again. This parameter defaults to the current date and time.

If the job fails to be executed successfully for some reason, oracle will retry 16 times and still fail to execute successfully, it will be marked as broken, and restart the job whose status is broken. There are two ways as follows: 
a. Use dbms_job. run() executes the job immediately 
begin 
  dbms_job.run(:job) -- the job is the job number returned when the submit process is submitted or go to dba_jobs to find the number 
end of the corresponding job;

b. Use dbms_job.broken() to re-mark the broken as false 
begin 
  dbms_job.broken (:job, false, next_date) 
end;

2. The change() process is used to change the settings of the specified job. 
This process has four parameters: job, what, next_date, 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 this job. 
The what parameter is a block of PL/SQL code to be run by this job. 
The next_date parameter indicates when this job will be executed. 
The interval parameter indicates how often a job should be re-executed.

3. The interval() procedure is used to explicitly set the number of time intervals between repeated executions of a job.  
This process has two parameters: job, interval. 
procedure interval( 
    job IN binary_integer, 
    interval IN varchar2 

The job parameter identifies a specific job. 
The interval parameter indicates how often a job should be re-executed.

4. The issubmit() process is used to submit a job with a specific job number.  
This procedure has five parameters: job, what, next_date, interval, no_parse. 
procedure issubmit ( 
    job IN binary_ineger, 
    what IN varchar2, 
    next_date IN date, 
    interval IN varchar2, 
    no_parse IN booean := FALSE 

The only difference between this procedure and the submit() procedure is that the job parameter is passed as an IN parameter and includes a The job number provided by the user. An error will be generated if the provided job number is already in use.

5. The next_date() procedure is used to explicitly set the execution time of a job. This procedure receives two parameters: job, next_date. 
procedure next_date( 
    job IN binary_ineger, 
    next_date IN date 

job identifies an existing job. 
The next_date parameter indicates the date and time when this job should be executed.

6. The remove() procedure removes a job that has been scheduled to run. This procedure accepts one 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 by calling the submit() procedure for this job. A job that is already running cannot be removed.

7、run()过程用来立即执行一个指定的job。这个过程只接收一个参数: 
procedure run(job IN binary_ineger) 
job参数标识将被立即执行的工作。

8、使用submit()过程,job被正常地计划。上面以讲述

9、user_export()过程返回一个命令,此命令用来安排一个存在的job以便此job能重新提交。此程序有两个参数:job、my_call。 
procedure user_export( 
    job IN binary_ineger, 
    my_call IN OUT varchar2 

job参数标识一个安排了的工作。 
my_call参数包含在它的当前状态重新提交此job所需要的正文。

10、what()过程应许在job执行时重新设置此正在运行的命令。这个过程接收两个参数:job、what。 
procedure what ( 
    job IN binary_ineger, 
    what IN OUT varchar2 

job参数标识一个存在的工作。 
what参数指示将被执行的新的PL/SQL代码。实现的功能:每隔一分钟自动向getSysDate表中插入当前的系统时间。




Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324967882&siteId=291194637