Oracle: Chain anlegen

Über den Oracle DBMS_Scheduler kann man simultan Jobs ausführen. Das Beispiel benötigt die Rechte "Create Job", "Create Rule", "Create Rule Set", "Create Evaluation Context", "Manage Scheduler". Hier ein Beispiel.
-- Test der simultanen Ausführungen von Programmen über den Scheduler
-- Die Chain startet P1, danach simultan P2 und P3 und schließlich P4
Set    Termout Off
Set    Feed Off
Set    Pagesize 200
Drop   Table T1;
Create Table T1 ( P Number, A Number );
Drop   Sequence A1;
Create Sequence A1;
execute DBMS_Scheduler.stop_job('J1');
execute DBMS_Scheduler.drop_job('J1');
execute DBMS_Scheduler.drop_chain('C1');
execute DBMS_Scheduler.drop_program('P1');
execute DBMS_Scheduler.drop_program('P2');
execute DBMS_Scheduler.drop_program('P3');
execute DBMS_Scheduler.drop_program('P4');
Clear
Set Termout On

Prompt  Install Chain
Execute DBMS_Scheduler.create_program('P1','PLSQL_BLOCK','Begin Insert Into T1 Values(1,A1.NextVal); Commit;End;',enabled=>true);
Execute DBMS_Scheduler.create_program('P2','PLSQL_BLOCK','Declare I Integer; Begin For I In 1..10000 Loop If MOD(i,1000)=0 Then Insert Into T1 Values(2,A1.NextVal); End If; Commit; End Loop; End;',enabled=>true);
Execute DBMS_Scheduler.create_program('P3','PLSQL_BLOCK','Declare I Integer; Begin For I In 1..10000 Loop If MOD(i,1000)=0 Then Insert Into T1 Values(3,A1.NextVal); End If; Commit; End Loop; End;',enabled=>true);
Execute DBMS_Scheduler.create_program('P4','PLSQL_BLOCK','Begin Insert Into T1 Values(4,A1.NextVal); Commit;End;',enabled=>true);
Execute DBMS_Scheduler.create_chain('C1');
Execute DBMS_Scheduler.define_chain_step('C1','S1','P1');
Execute DBMS_Scheduler.define_chain_step('C1','S2','P2');
Execute DBMS_Scheduler.define_chain_step('C1','S3','P3');
Execute DBMS_Scheduler.define_chain_step('C1','S4','P4');
Execute DBMS_Scheduler.define_chain_rule('C1','TRUE','START S1');
Execute DBMS_Scheduler.define_chain_rule('C1','S1 COMPLETED','START S2');
Execute DBMS_Scheduler.define_chain_rule('C1','S1 COMPLETED','START S3');
Execute DBMS_Scheduler.define_chain_rule('C1','S2 COMPLETED AND S3 COMPLETED','START S4');
Execute DBMS_Scheduler.define_chain_rule('C1','S4 COMPLETED','END');
Execute DBMS_Scheduler.enable('C1');
Prompt  Create Job
Execute DBMS_Scheduler.create_job('J1','CHAIN','C1',start_date=>SYSDATE,enabled=>TRUE);
Execute Dbms_Lock.sleep(1);
Prompt  Result
Select  * from T1 Order by A;
Stefan-Taube.de