CREATE OR REPLACE FUNCTION BUSCA_OBSERVACAO_CLIENTE(P_CDCLIENTE IN CLIENTE.CDCLIENTE%TYPE)RETURN LONG RAW
AS
   V_DSOBSERVCLIE OBSERVCLIE.DSOBSERVCLIE%TYPE;
BEGIN
   V_DSOBSERVCLIE := NULL;
   BEGIN
      SELECT O.DSOBSERVCLIE
        INTO V_DSOBSERVCLIE
        FROM OBSERVCLIE O
       WHERE O.CDCLIENTE = P_CDCLIENTE
         AND (O.DTHROBSCLIE = (SELECT DTHROBSCLIE
                                 FROM (SELECT O1.DTHROBSCLIE
                                         FROM OBSERVCLIE O1
                                        WHERE O1.CDCLIENTE = O.CDCLIENTE
                                          AND O1.CDCLIENTE = O.CDCLIENTE
                                       ORDER BY 1 DESC)
                               WHERE ROWNUM = 1));
   EXCEPTION
      WHEN NO_DATA_FOUND THEN BEGIN
         V_DSOBSERVCLIE := NULL;
      END;
   END;

   RETURN(V_DSOBSERVCLIE);
END;
/