CREATE OR REPLACE FUNCTION CTB_CCTBL_TIPOCONTAFIL(
P_CDTIPOCONTA IN TIPOCTPAGARFILI.CDTPCTPAGAR%TYPE,
P_CDFILIAL IN FILIAL.CDFILIAL%TYPE) RETURN VARCHAR2
AS
   V_CONTA VARCHAR2(20);
BEGIN
   V_CONTA := NULL;
   BEGIN
      SELECT TF.CDCONTCTBL
        INTO V_CONTA
        FROM TIPOCTPAGARFILI TF
       WHERE TF.CDTPCTPAGAR = P_CDTIPOCONTA
         AND TF.CDFILIAL = P_CDFILIAL;
   EXCEPTION
      WHEN NO_DATA_FOUND THEN
         V_CONTA := NULL;
   END;

   IF V_CONTA IS NULL THEN
      BEGIN
         SELECT T.CDCONTCTBL
           INTO V_CONTA
           FROM TIPOCTPAGAR T
          WHERE T.CDTPCTPAGAR = P_CDTIPOCONTA;
      EXCEPTION
         WHEN NO_DATA_FOUND THEN
            V_CONTA := NULL;
      END;
   END IF;
   RETURN V_CONTA;
END;
/

-- VERSAO --
BEGIN ATUVEROBJ('CTB_CCTBL_TIPOCONTAFIL','5.50.000'); END;
/
