CREATE OR REPLACE FUNCTION fn_fco_tratar_NIT (i_cia IN CHAR)
RETURN CHAR
IS
   w_nit char(30);
BEGIN
   SELECT registro_fiscal 
   INTO w_nit
   FROM COMPANIAS
   WHERE compania=i_cia;

   IF InStr(w_nit, '.') > 0 THEN
      SELECT SubStr(registro_fiscal,1,3) || SubStr(registro_fiscal,5,3) || SubStr(registro_fiscal,9,3)
      INTO w_nit
      FROM COMPANIAS WHERE compania=i_cia;
   ELSE
      SELECT SubStr(registro_fiscal,1,9) 
      INTO w_nit
      FROM COMPANIAS WHERE compania=i_cia;
   END IF;
RETURN(w_nit);
END;
/
CREATE PUBLIC SYNONYM fn_fco_tratar_NIT FOR ADAM.fn_fco_tratar_NIT;
GRANT ALL ON fn_fco_tratar_NIT TO ADAMA;
