Oracle Consulting Oracle Training Development

Remote DBA

Remote DBA Plans  

Remote DBA Service

Remote DBA RAC

   
Remote DBA Oracle Home
Remote DBA Oracle Training
Remote DBA SQL Tuning Consulting
Remote DBA Oracle Tuning Consulting
Remote DBA Data Warehouse Consulting
Remote DBA Oracle Project Management
Remote DBA Oracle Security Assessment
Remote DBA Unix Consulting
Burleson Books
Burleson Articles
Burleson Web Courses
Burleson Qualifications
Oracle Links
Remote DBA Oracle Monitoring
Remote DBA Support Benefits
Remote DBA Plans & Prices
Our Automation Strategy
What We Monitor
Oracle Apps Support
Print Our Brochure
Contact Us (e-mail)
Oracle Job Opportunities
Oracle Consulting Prices





   

 

 

 

Remote DBA services

Remote DBA Support

Remote DBA RAC

Remote DBA Reasons

Remote Oracle Tuning

Remote DBA Links

Oracle DBA Support

Oracle DBA Forum

Oracle Disaster

Oracle Training

Oracle Tuning

Oracle Training

 Remote DBA SQL Server

Remote MSSQL Consulting

Oracle DBA Hosting

Oracle License Negotiation

 

 


 

 

 

        
 

 Oracle Job Scheduler Conditional Job Enabling
Oracle Tips by Burleson Consulting

Advanced Oracle Utilities: The Definitive Reference by Rampant TechPress is written by four of the top Oracle database experts (Bert Scalzo, Donald Burleson, and Steve Callan).  The following is an excerpt from the book.

In this method, all tasks in the chain are scheduled as regular repeating jobs, but only the first job in the chain is enabled.  All subsequent jobs in the chain are disabled or marked as broken prior to Oracle.  As each task in the chain completes successfully, it enables the next task in the chain by enabling its associated job.  Every time the first task runs, it disables the chain before starting again.

 

The job_chain_enable.sql script creates a package specification and body that will do all the work for the example job chain.

 

job_chain_enable.sql

 

CREATE OR REPLACE PACKAGE job_chain_enable AS

 

PROCEDURE task_1;

PROCEDURE task_2;

PROCEDURE task_3;

 

END job_chain_enable;

/

SHOW ERRORS

 

 

CREATE OR REPLACE PACKAGE BODY job_chain_enable AS

 

-- -----------------------------------------------------------------

PROCEDURE task_1 AS

-- -----------------------------------------------------------------

BEGIN

 

  -- Disable dependent jobs

  -- Oracle

  DBMS_SCHEDULER.disable ('job_chain_enable_task_2');

  DBMS_SCHEDULER.disable ('job_chain_enable_task_3');

 

 

  DELETE FROM job_chain;

 

  INSERT INTO job_chain (created_timestamp, task_name)

  VALUES (systimestamp, 'TASK_1');

  COMMIT;

 

  -- Uncomment the following line to force a failure.

  --RAISE_APPLICATION_ERROR(-20000,

  --  'This is a fake error to prevent task_2 being executed');

 

  -- The work has comleted successfully so enable task_2

  -- Oracle

  DBMS_SCHEDULER.enable ('job_chain_enable_task_2');

   

EXCEPTION

  WHEN OTHERS THEN

    -- Don't enable task_2.

    NULL;

END task_1;

-- -----------------------------------------------------------------

 

-- -----------------------------------------------------------------

PROCEDURE task_2 AS

-- -----------------------------------------------------------------

BEGIN

 

  INSERT INTO job_chain (created_timestamp, task_name)

  VALUES (systimestamp, 'TASK_2');

  COMMIT;

 

  -- Uncomment the following line to force a failure.

  --RAISE_APPLICATION_ERROR(-20000,

  --  'This is a fake error to prevent task_3 being executed');

 

  -- The work has comleted successfully so enable task_3

  -- Oracle

  DBMS_SCHEDULER.enable ('job_chain_enable_task_3');

   

EXCEPTION

  WHEN OTHERS THEN

    -- Don't enable task_3.

    NULL;

END task_2;

-- -----------------------------------------------------------------

 

-- -----------------------------------------------------------------

PROCEDURE task_3 AS

-- -----------------------------------------------------------------

BEGIN

 

  INSERT INTO job_chain (created_timestamp, task_name)

  VALUES (systimestamp, 'TASK_3');

  COMMIT;

 

END task_3;

-- -----------------------------------------------------------------

 

END job_chain_enable;

/

SHOW ERRORS

 

Since no jobs are created by the code, they must all be created in advance using the job_chain_enable_jobs.sql script.  The jobs must persist, so they are generated with repeat intervals.  These repeat intervals schedule them to run at 06:00, 12:00 and 18:00 respectively.  Commands to remove the jobs are included and should be run once the example is completed.

 

job_chain_enable_jobs.sql

 

-- Oracle

BEGIN

  DBMS_SCHEDULER.create_job (

    job_name        => 'job_chain_enable_task_1',

    job_type        => 'STORED_PROCEDURE',

    job_action      => 'job_chain_enable.task_1',

    start_date      => SYSTIMESTAMP,

    repeat_interval => 'freq=daily; byhour=6; byminute=0; bysecond=0;',

    end_date        => NULL,

    enabled         => TRUE,

    comments        => 'First task in the enable chain.');

END;

/

 

BEGIN

  DBMS_SCHEDULER.create_job (

    job_name        => 'job_chain_enable_task_2',

    job_type        => 'STORED_PROCEDURE',

    job_action      => 'job_chain_enable.task_2',

    start_date      => SYSTIMESTAMP,

    repeat_interval => 'freq=daily; byhour=12; byminute=0; bysecond=0;',

    end_date        => NULL,

    enabled         => FALSE,

    comments        => 'Second task in the enable chain.');

END;

/

 

BEGIN

  DBMS_SCHEDULER.create_job (

    job_name        => 'job_chain_enable_task_3',

    job_type        => 'STORED_PROCEDURE',

    job_action      => 'job_chain_enable.task_3',

    start_date      => SYSTIMESTAMP,

    repeat_interval => 'freq=daily; byhour=18; byminute=0; bysecond=0;',

    end_date        => NULL,

    enabled         => FALSE,

    comments        => 'Third task in the enable chain.');

END;

/

 

 

-- Cleanup

/*

-- Oracle

BEGIN

  DBMS_SCHEDULER.drop_job ('job_chain_enable_task_3');

  DBMS_SCHEDULER.drop_job ('job_chain_enable_task_2');

  DBMS_SCHEDULER.drop_job ('job_chain_enable_task_1');

END;

/

     

Remote DBA Service
 

Oracle Tuning Book

 

Advance SQL Tuning Book 

BC Oracle support

Oracle books by Rampant

Oracle monitoring software

 

 

 

 

 

 

 

 

 

BC Remote Oracle Support

Remote DBA

Remote DBA Services

Copyright © 1996 -  2013 by Burleson. All rights reserved.

Oracle® is the registered trademark of Oracle Corporation.