CREATE OR REPLACE PROCEDURE HRIS_JOBS_PROC
AS
BEGIN
  FOR jobs IN
  (SELECT * FROM HRIS_JOBS WHERE EXECUTED ='N'
  )
  LOOP
    BEGIN
      EXECUTE IMMEDIATE jobs.WHAT;
      UPDATE HRIS_JOBS
      SET EXECUTED  ='Y',
        STATUS      ='S',
        EXECUTED_AT =SYSDATE
      WHERE JOB_ID  = jobs.JOB_ID;
    EXCEPTION
    WHEN OTHERS THEN
      UPDATE HRIS_JOBS
      SET EXECUTED  ='Y',
        STATUS      ='F',
        EXECUTED_AT =SYSDATE
      WHERE JOB_ID  = jobs.JOB_ID;
    END;
COMMIT;
  END LOOP;
END;