Home » SQL & PL/SQL » SQL & PL/SQL » To check hanging/not run/failed jobs (oracle Database 10g Enterprise Edition Release 10.2.0.4.0)
To check hanging/not run/failed jobs [message #597259] Wed, 02 October 2013 04:30 Go to next message
gopal.biswal
Messages: 11
Registered: October 2013
Location: Pune
Junior Member
Hi,
I am trying create a PL/SQL script to check if any scheduled database jobs failed in last 10 minutes or has not run/or hanging since last 10 minutes. Please note that I am not aware of any built-in already available for this. Can you please suggest on the below code.
Please note that interval of the job run is 1 minute.

DECLARE
   -- V_CNT   NUMBER := 0;
   V_STATUS   user_scheduler_job_run_details.STATUS%TYPE;
BEGIN
   FOR I IN (SELECT ENABLED_FLAG
               FROM JOB_STATUS
              WHERE job_name = 'JOB_NAME')
   LOOP
      IF I.ENABLED_FLAG = 'E'     --Not allowed to check in Maintenance window
      THEN
         BEGIN
            SELECT ASJRD.STATUS
              INTO V_STATUS
              from user_scheduler_job_run_details asjrd
             WHERE asjrd.job_name = 'JOB_NAME'
                   AND (   SYSDATE - (1 / (24 * 60) * 10) <= ASJRD.log_date
                        OR (    SYSDATE - (1 / (24 * 60) * 10) <=
                                   ASJRD.log_date
                            AND ASJRD.STATUS <> 'FAILED'))
                   AND ROWNUM = 1;
         EXCEPTION
            WHEN NO_DATA_FOUND                    --No rows in last 10 minutes
            THEN
               raise_application_error (
                  -20101,
                  'No rows found for the last 10 minutes');
         END;
 
 
         IF (V_STATUS = 'FAILED')                   --Error in last 10 minutes
         THEN
            raise_application_error (-20101,
                                     'Error found for the last 10 minutes');
         END IF;
      END IF;
   END LOOP;
END;         
 


JOB_STATUS is a application table which contains Job name,enabled etc.
Database version is oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Thanks.
-Gk

[Updated on: Fri, 04 October 2013 10:41] by Moderator

Report message to a moderator

Re: To check hanging/not run/failed jobs [message #597264 is a reply to message #597259] Wed, 02 October 2013 05:27 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
I see the JOB_NAME is hardcoded. That implies, you will run the script manually, since, if you want to schedule it to run in certain interval then it should be dynamic. Any specific reason for doing it in PL/SQL?

Regards,
Lalit
Re: To check hanging/not run/failed jobs [message #597400 is a reply to message #597259] Fri, 04 October 2013 07:16 Go to previous messageGo to next message
tigsav
Messages: 49
Registered: April 2012
Member
Hi,

Adding to lalit's point , How can v_status be 'FAILED' if what you are selecting has a where clause saying status <>'FAILED'.
Or Am i missing Something.

Regards,
tigsav
icon13.gif  Re: To check hanging/not run/failed jobs [message #597422 is a reply to message #597400] Fri, 04 October 2013 10:43 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Quote:
How can v_status be 'FAILED' if what you are selecting has a where clause saying status <>'FAILED'.
Or Am i missing Something.


You are missing the OR.

icon4.gif  Re: To check hanging/not run/failed jobs [message #597423 is a reply to message #597259] Fri, 04 October 2013 10:50 Go to previous message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Quote:
   SYSDATE - (1 / (24 * 60) * 10) <= ASJRD.log_date
                        OR (    SYSDATE - (1 / (24 * 60) * 10) <=
                                   ASJRD.log_date
                            AND ASJRD.STATUS <> 'FAILED')


A or (A and B) is equivalent to A (as B is never NULL).
Or, taking account of NULL, "A or (A and B)" is TRUE if and only if A is TRUE.

[Updated on: Fri, 04 October 2013 10:50]

Report message to a moderator

Previous Topic: Loading Data from one remote Server into another Remote server Database....
Next Topic: Calling .sql file from .ksh file
Goto Forum:
  


Current Time: Thu Apr 25 19:00:58 CDT 2024