You can schedule a stored procedure to run at a particular time, at an interval, or when
a specified event occurs. The administrative task scheduler manages these requests.
Procedure
To schedule execution of a stored procedure:
-
Add a task for the administrative task scheduler by using the ADMIN_TASK_ADD stored procedure.
When you add your task, specify which stored procedure to run and when to run it.
Use one of the following parameters or groups of parameters of ADMIN_TASK_ADD to control when
the stored procedure is run:
Option |
Description |
interval |
The stored procedure is to execute at the specified regular interval. |
point-in-time |
The stored procedure is to execute at the specified times. |
trigger-task-name |
The stored procedure is to execute when the specified task occurs. |
trigger-task-name
trigger-task-cond
trigger-task-code |
The stored procedure is to execute when the specified task and task result occur. |
Optionally, you can also use one or more of the following parameters to control when the
stored procedure runs:
- begin-timestamp
- Earliest permitted execution time
- end-timestamp
- Latest permitted execution time
- max-invocations
- Maximum number of executions
When the specified time or event occurs for the stored procedure to run, the
administrative task scheduler calls the stored procedure in Db2.
- Optional:
After the task finishes execution, check the status by using the ADMIN_TASK_STATUS
function.
This function returns a table with one row that indicates the last execution status for
each scheduled task. If the scheduled task is a stored procedure, the JOB_ID, MAXRC,
COMPLETION_TYPE, SYSTEM_ABENDCD, and USER_ABENDCD fields contain null values. In the case of a Db2 error, the SQLCODE, SQLSTATE, SQLERRMC, and SQLERRP fields
contain the information that Db2 returned from calling the
stored procedure.