CREATE OR REPLACE FUNCTION BUSCA_CCUSTO(P_CDFILIAL IN VARCHAR, P_CDEMPRESA IN VARCHAR) RETURN VARCHAR
IS
   V_CDCENTCUST VARCHAR2(04);
BEGIN
   BEGIN
      SELECT CDCENTCUST
        INTO V_CDCENTCUST
        FROM FILIAL
       WHERE CDFILIAL = P_CDFILIAL;
   EXCEPTION
      WHEN NO_DATA_FOUND THEN
         V_CDCENTCUST := NULL;
   END;
   IF V_CDCENTCUST IS NULL THEN
      BEGIN
         SELECT CDCENTCUST
           INTO V_CDCENTCUST
           FROM EMPRESA
          WHERE CDEMPRESA = P_CDEMPRESA;
      EXCEPTION
         WHEN NO_DATA_FOUND THEN
            V_CDCENTCUST := NULL;
      END;
   END IF;


   RETURN(V_CDCENTCUST);
END;
/


-- VERSAO --
BEGIN ATUVEROBJ('BUSCA_CCUSTO','5.70.000'); END;
/

