An Oracle Job Chain is a feature of DBMS_SCHEDULER that organizes multiple executable steps into a single workflow.
A chain controls the execution order, dependencies, parallel processing, synchronization, and failure handling of its steps.
Unlike a regular Scheduler job, a Job Chain can execute several programs sequentially or concurrently and start subsequent operations based on the results of previous steps.
CREATE_CHAINCreates the chain structure.
BEGIN
DBMS_SCHEDULER.CREATE_CHAIN(
chain_name => 'DWH_CHAIN',
comments => 'DWH processing chain'
);
END;
/
CREATE_PROGRAMDefines the operations executed by chain steps.
BEGIN
DBMS_SCHEDULER.CREATE_PROGRAM(
program_name => 'PRG_JOB_1',
program_type => 'STORED_PROCEDURE',
program_action => 'PRC_JOB_1',
enabled => TRUE
);
END;
/
The stored procedure PRC_JOB_1 must already exist.
DEFINE_CHAIN_STEPAssociates Scheduler programs with chain steps.
BEGIN
DBMS_SCHEDULER.DEFINE_CHAIN_STEP(
chain_name => 'DWH_CHAIN',
step_name => 'JOB_1',
program_name => 'PRG_JOB_1'
);
END;
/
DEFINE_CHAIN_RULEDefines when a step executes.
BEGIN
DBMS_SCHEDULER.DEFINE_CHAIN_RULE(
chain_name => 'DWH_CHAIN',
condition => 'TRUE',
action => 'START JOB_1',
rule_name => 'RULE_1'
);
END;
/
ENABLEActivates the chain for execution.
BEGIN
DBMS_SCHEDULER.ENABLE(
name => 'DWH_CHAIN'
);
END;
/
CREATE_JOBCreates a Scheduler job associated with the chain.
BEGIN
DBMS_SCHEDULER.CREATE_JOB(
job_name => 'JOB_DWH_CHAIN',
job_type => 'CHAIN',
job_action => 'DWH_CHAIN',
enabled => TRUE,
auto_drop => FALSE
);
END;
/
RUN_JOBStarts the chain.
BEGIN
DBMS_SCHEDULER.RUN_JOB(
job_name => 'JOB_DWH_CHAIN',
use_current_session => FALSE
);
END;
/
Displays currently running chain steps.
SELECT owner,
job_name,
job_subname,
state
FROM dba_scheduler_running_chains
WHERE job_name = 'JOB_DWH_CHAIN';
START
|
+--> JOB_1 --> SUCCEEDED
|
+--> JOB_2 --> SUCCEEDED
|
+--> JOB_3 --> RUNNING
Steps execute one after another, depending on the preceding step's result.
JOB_1
JOB_2
JOB_3
END
condition => 'TRUE',
action => 'START JOB_1'
condition => 'JOB_1 SUCCEEDED',
action => 'START JOB_2'
condition => 'JOB_2 SUCCEEDED',
action => 'START JOB_3'
condition => 'JOB_3 SUCCEEDED',
action => 'END'
Each condition/action pair represents a separate chain rule.
START
|
+--> JOB_1 --> SUCCEEDED --+
| |
+--> JOB_2 --> SUCCEEDED --+--> END
| |
+--> JOB_3 --> SUCCEEDED --+
Multiple steps start independently and can execute concurrently.
START CHAIN
JOB_1
JOB_2
JOB_3
END CHAIN
condition => 'TRUE',
action => 'START JOB_1'
condition => 'TRUE',
action => 'START JOB_2'
condition => 'TRUE',
action => 'START JOB_3'
condition => 'JOB_1 SUCCEEDED AND
JOB_2 SUCCEEDED AND
JOB_3 SUCCEEDED ',
action => 'END'
START
|
+--> JOB_1 --> SUCCEEDED --+
| |
+--> JOB_2 --> SUCCEEDED --+--> FINAL_CALCULATION --> END
| |
+--> JOB_3 --> SUCCEEDED --+
Three steps execute concurrently. A final step starts after all three complete.
START CHAIN
JOB_1
JOB_2
JOB_3
ALL THREE COMPLETED
FINAL_CALCULATION
END
condition => 'JOB_1 SUCCEEDED AND
JOB_2 SUCCEEDED AND
JOB_3 SUCCEEDED ',
action => 'START FINAL_CALCULATION'
condition => 'FINAL_CALCULATION SUCCEEDED',
action => 'END'
START CHAIN
|
v
JOB_1
|
+-- SUCCEEDED --> JOB_2
| |
| +-- SUCCEEDED --> JOB_3
| | |
| | +-- SUCCEEDED --> END SUCCESS
| | |
| | +-- FAILED ----> END ERROR 20003
| |
| +-- FAILED -----------------------> END ERROR 20002
|
+-- FAILED ----> ERROR_HANDLER
|
+-- SUCCEEDED --> END ERROR 20001
|
+-- FAILED ----> END ERROR 20004
Execution follows different paths depending on the step's result.
JOB_1
SUCCEEDED
JOB_2
END
FAILED
ERROR HANDLING
END ERROR
condition => 'JOB_1 SUCCEEDED',
action => 'START JOB_2'
condition => 'JOB_1 FAILED',
action => 'END 20001'
|
Parameter |
Description |
|---|---|
|
|
Name of the chain |
|
|
Logical expression controlling execution |
|
|
Operation performed when the condition is true |
|
|
Unique rule name |
|
|
Optional description |
|
Condition |
Description |
|---|---|
|
|
Unconditionally satisfied |
|
|
Step completed successfully |
|
|
Step failed |
|
|
Step completed |
|
|
Step was stopped |
|
|
Step is executing |
|
|
Step has not started |
|
|
Numeric error code |
Logical operators include AND, OR, NOT, and parentheses.
|
Action |
Description |
|---|---|
|
|
Starts a step |
|
|
Stops a running step |
|
|
Ends the chain successfully |
|
|
Ends the chain with an error |
|
Method |
Description |
|---|---|
|
|
Creates a chain |
|
|
Creates an executable program |
|
|
Adds a chain step |
|
|
Defines execution rules |
|
|
Modifies chain or step attributes |
|
|
Enables Scheduler objects |
|
|
Disables Scheduler objects |
|
|
Creates a Scheduler job |
|
|
Executes a job |
|
|
Stops a running job |
|
|
Removes a rule |
|
|
Removes a step |
|
|
Removes a chain |
|
View |
Description |
|---|---|
|
|
Chain definitions |
|
|
Chain steps |
|
|
Execution rules |
|
|
Currently running chain steps |
|
|
Active Scheduler jobs |
|
|
Execution history |
|
|
Job activity |
Important: Chain steps execute according to rule conditions, not the order in which the rules were created. Parallel execution is achieved through independent start rules, without a dedicated parallelism parameter.