## Overcoming "outer join" limitations via "inline" stored functions

    SELECT E.emp_no, E.emp_name, H.hist_date, H.Hist_Type
    From   emp_historty H,
           emp E
    Where  E.emp_no        = :emp_no
    And    E.emp_no        = H.emp_no (+)
    And    H.hist_date (+) = ( SELECT MAX(hist_date)
    And                        From   emp_history
                               Where  emp_no = E.emp_no );


## This statement is illegal. Try using an inline stored function.

    FUNCTION Max_Emp_History (emp IN number) return date
    AS
      max_dte date;
      CURSOR  C1 IS
      SELECT  MAX(hist_date) 
      FROM    emp_history
      WHERE   emp_no = emp;
    BEGIN
      Open  C1;
      Fetch C1 into max_dte;
      Close C1;
      return (max_dte);
    END;


    SELECT E.emp_no, E.emp_name, H.hist_date, H.Hist_Type
    From   emp_historty H,
           emp E
    Where  E.emp_no        = :emp_no
    And    E.emp_no        = H.emp_no (+)
    And    H.hist_date (+) = Max_Emp_History (E.emp_no);
