DECLARE
  V_JOB_HISTORY_ID NUMBER;
BEGIN
  FOR EMP IN
  (SELECT  *
  FROM HRIS_EMPLOYEES
  WHERE EMPLOYEE_ID NOT IN
    (SELECT DISTINCT EMPLOYEE_ID FROM HRIS_JOB_HISTORY WHERE STATUS = 'E'
    )
  )
  LOOP
    SELECT MAX(JOB_HISTORY_ID) + 1 INTO V_JOB_HISTORY_ID FROM HRIS_JOB_HISTORY;
    INSERT
    INTO HRIS_JOB_HISTORY
      (
        JOB_HISTORY_ID,
        EMPLOYEE_ID,
        START_DATE,
        SERVICE_EVENT_TYPE_ID,
        TO_COMPANY_ID,
        TO_BRANCH_ID,
        TO_DEPARTMENT_ID,
        TO_DESIGNATION_ID,
        TO_POSITION_ID,
        TO_SERVICE_TYPE_ID,
        TO_SALARY
      )
      VALUES(V_JOB_HISTORY_ID,EMP.EMPLOYEE_ID,EMP.JOIN_DATE,2,EMP.COMPANY_ID,EMP.BRANCH_ID,EMP.DEPARTMENT_ID,EMP.DESIGNATION_ID,EMP.POSITION_ID,EMP.SERVICE_TYPE_ID,EMP.SALARY);
  END LOOP;
END;
