CREATE OR REPLACE FUNCTION VERIF_TIPORETI_CONSREAL(
   P_CDFILIAL     IN FILIAL.CDFILIAL%TYPE,
   P_NRLANCESTQ   IN LANCTOESTOQ.NRLANCESTQ%TYPE) RETURN VARCHAR
IS
   V_NMTIPORETI   VARCHAR2(40);
BEGIN
   BEGIN
      SELECT MAX(NMTIPORETI)
        INTO V_NMTIPORETI
        FROM ITLANCTOEST I, TIPORETI T
       WHERE I.CDFILIAL   = P_CDFILIAL
         AND I.NRLANCESTQ = P_NRLANCESTQ
         AND T.CDTIPORETI = I.CDTIPORETI;
   EXCEPTION
      WHEN NO_DATA_FOUND THEN
      V_NMTIPORETI := NULL;
   END;

   RETURN(V_NMTIPORETI);
END;
/