3. Add Rules
Chain rules define when steps are run, and define dependencies between steps. All chain rules work together to define the overall action of the chain. When the chain job starts and at the end of each step, all rules are evaluated to see what action or actions occur next. If more than one rule has a TRUE condition, multiple actions can occur. Listing 7 shows the rules for my chain named REFRESH_TEST.REFRESH_PROC.
BEGIN
SYS.DBMS_SCHEDULER.DEFINE_CHAIN_RULE (
chain_name => 'REFRESH_TEST.REFRESH_PROC'
,condition => 'TRUE'
,action => 'START "REMOVE_DUMP_FILE"'
,rule_name => 'REFRESH_TEST.RULE_100'
,comments => 'Start The Refresh Process');
SYS.DBMS_SCHEDULER.DEFINE_CHAIN_RULE (
chain_name => 'REFRESH_TEST.REFRESH_PROC'
,condition => 'REMOVE_DUMP_FILE SUCCEEDED'
,action => 'START "EXPORT_PROD"'
,rule_name => 'REFRESH_TEST.RULE_200'
,comments => 'Export The Data from Prod');
SYS.DBMS_SCHEDULER.DEFINE_CHAIN_RULE (
chain_name => 'REFRESH_TEST.REFRESH_PROC'
,condition => 'export_prod SUCCEEDED'
,action => 'START "CLEAR_SCHEMA"'
,rule_name => 'REFRESH_TEST.RULE_300'
,comments => 'Clear the Test Data');
SYS.DBMS_SCHEDULER.DEFINE_CHAIN_RULE (
chain_name => 'REFRESH_TEST.REFRESH_PROC'
,condition => 'clear_schema SUCCEEDED'
,action => 'START "IMPORT_PROD"'
,rule_name => 'REFRESH_TEST.RULE_400'
,comments => 'Import Data Into Test');
SYS.DBMS_SCHEDULER.DEFINE_CHAIN_RULE (
chain_name => 'REFRESH_TEST.REFRESH_PROC'
,condition => 'import_prod SUCCEEDED'
,action => 'START "CLEANUP"'
,rule_name => 'REFRESH_TEST.RULE_500'
,comments => 'Cleanup Data');
SYS.DBMS_SCHEDULER.DEFINE_CHAIN_RULE (
chain_name => 'REFRESH_TEST.REFRESH_PROC'
,condition => 'cleanup SUCCEEDED'
,action => 'START "SEND_EMAIL"'
,rule_name => 'REFRESH_TEST.RULE_600'
,comments => ' Sending Email');
SYS.DBMS_SCHEDULER.DEFINE_CHAIN_RULE (
chain_name => 'REFRESH_TEST.REFRESH_PROC'
,condition => 'SEND_EMAIL SUCCEEDED'
,action => 'END 0'
,rule_name => 'REFRESH_TEST.RULE_700'
,comments => 'Successful Job Chain Ending');
End;
Note: The first chain rule has an action of "Start" and the last chain rule has an action of "End".


