CREATE OR REPLACE FUNCTION VERIF_ENTRADA_OP(
   P_CDFILIAL     IN FILIAL.CDFILIAL%TYPE,
   P_NRLANCESTQ   IN LANCTOESTOQ.NRLANCESTQ%TYPE) RETURN VARCHAR
IS
   V_NRORDPROD   VARCHAR2(10);
BEGIN
   BEGIN
      SELECT MAX(NRORDPROD)
        INTO V_NRORDPROD
        FROM PRODACABADO
       WHERE CDFILIAL   = P_CDFILIAL
         AND NRLANCESTQ = P_NRLANCESTQ;
   EXCEPTION
      WHEN NO_DATA_FOUND THEN
      V_NRORDPROD := NULL;
   END;

   RETURN(V_NRORDPROD);
END;
/