Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

DBMS_SCHEDULER how to get last executed time

StarFeb 1 2012 — edited Feb 2 2012
Hi,

I have one of the dbms_job scheduled.
In this job I am executing on procedure p_test
In the procedure I want to know last job executed time.
However, I don't know how to get last exected time?
Can you please help?

CREATE TABLE JOB_TIMING
(	job_name	VARCHAR2(100),
	current_time	VARCHAR2(100),
	last_executed_time  VARCHAR2(100)
) ;




CREATE OR REPLACE PROCEDURE P_TEST
IS
v_last_time varchar2(100);
v_current_time varchar2(100);
BEGIN
        --Current_time
         v_current_time := TO_CHAR( SYSDATE  ,'HH24:MI');


        --Here I DON'T KNOW HOW TO GET LAST EXECUTED TIME.
        --CAN YOU PLEASE HELP
        --as per current scheduled frequency last executed time should be 30 minute earlier.
        --But I don't want to hard code sysdate - 30 minute to get last executed time.

        SELECT TO_CHAR(last_start_date  ,'HH24:MI') INTO v_last_time
                 FROM  user_scheduler_jobs
                 WHERE JOB_name = 'my_dbms_job';


        INSERT INTO JOB_TIMING(job_name, current_time,last_executed_time )
        VALUES ('my_dbms_job',v_current_time,v_last_time);
        COMMIT;
END;


BEGIN
DBMS_SCHEDULER.CREATE_JOB (
   job_name             => 'my_dbms_job',
   job_type             => 'PLSQL_BLOCK',
   job_action           => 'BEGIN  P_TEST ; END;',
   start_date           =>  SYSDATE,
   repeat_interval      => 'freq=MINUTELY; interval=30; bysecond=0;', 
   end_date        		=>  NULL,
   enabled              =>  TRUE,
   comments             => 'Testing');
END;
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 1 2012
Added on Feb 1 2012
14 comments
4,184 views