0

I have a script /home/load_data.sh that I want to run from my procedure, only if my IF statement is not satisfied:

create or replace
PROCEDURE   RD_ODS_REFRESH_LOG 
IS
BEGIN 
 FOR i IN 
 (
    SELECT RESULT FROM USERS
    WHERE trunc(COMPLETED_DATE) = trunc(SYSDATE -1) 
 )
    LOOP
      IF i.RESULT = 'FAIL' 
      THEN 
          EMAIL
          (
              '[email protected]', 
              'daily Refresh report', 
              'FAILED', 
              'Todays daily Refresh Failed.'
          );
      ELSE
          SYS.DBMS_SCHEDULER.create_job 
          (
              job_name              => 'RD_ODS_REFRESH_LOG',
              job_action            => '/home/load_data.sh',
              job_type              => 'executable',
              number_of_arguments   => 0,
              start_date            => SYSDATE,
              repeat_interval       => 'FREQ=SECONDLY; INTERVAL=1',
              enabled               => FALSE,
              auto_drop             => FALSE,
              comments              => 'run load data shell script'
          );
          SYS.DBMS_SCHEDULER.SET_ATTRIBUTE
          ( 
              name => 'RD_ODS_REFRESH_LOG', 
              attribute => 'logging_level', value => DBMS_SCHEDULER.LOGGING_FULL
          );
          SYS.DBMS_SCHEDULER.enable
          (
              name => 'RD_ODS_REFRESH_LOG'
          );
      END IF;
    END LOOP;
END RD_ODS_REFRESH_LOG;

I am wondering how to put all of this together so that when IF is not satisfied, it jumps to ELSE statement and it executes the above code?

Can I use something else other than SCHEDULER? After all all I want is to be able to run my /home/load_data.sh script in ELSE case.

I use Oracle11g...

1 Answer 1

1

It might be worth going in the other direction and making more use of scheduler, in particular of scheduler chains.

I say this because the sort of flow control that you show here -- do X if fail, otherwise do Y -- is tiresome to code, and with a scheduler chain you simply specify the next step to run if particular steps raise an error or not.

Once you get used to it it's pretty pain free, and very flexible and reliable -- I ran scheduler chains to load a data warehouse, executing the load and transform job every 60 seconds 24 hours a day for over a year, stopping the chains for maintenance, starting them again when maintenance is over, and all you need are a few monitoring and control scripts.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.