CREATE OR REPLACE FUNCTION USR_DESC_DT_VENCIMENTO
   (P_CDFILIAL   IN  FILIAL.CDFILIAL%TYPE,
    P_NRLANCTONF IN  NOTAFISCAL.NRLANCTONF%TYPE) RETURN VARCHAR
IS
   V_RESULT     VARCHAR2(4000);
BEGIN
   V_RESULT   := NULL;

   FOR C_DATAS IN (SELECT TO_CHAR(NVL(DTATUAVENPAG, DTORIGVENPAG), 'DD-')|| 
                          TO_CHAR(TO_DATE(NVL(DTATUAVENPAG, DTORIGVENPAG)), 'MON')||TO_CHAR(NVL(DTATUAVENPAG, DTORIGVENPAG), '-YY') AS DTVENC
                    FROM CONTAPAGAR
                   WHERE CDFILIAL   = P_CDFILIAL
                     AND NRLANCTONF = P_NRLANCTONF
                   ORDER BY QTDIASVENPAG) LOOP

      IF V_RESULT IS NULL THEN
         V_RESULT := C_DATAS.DTVENC;
      ELSE
         V_RESULT := V_RESULT || ' - ' || C_DATAS.DTVENC;
      END IF;
   END LOOP;

   RETURN(V_RESULT);
END;
/

-- VERSAO --
BEGIN ATUVEROBJ('USR_DESC_DT_VENCIMENTO','6.39.010'); END;
/
