CREATE OR REPLACE FUNCTION RETIRA_CARACTER_ESPECIAL(
   P_TEXTO       IN VARCHAR2,
   P_RETIRA_PIPE IN VARCHAR2) RETURN VARCHAR2
AS
   V_TEXTO  VARCHAR2(4000);
   V_CHAR   VARCHAR2(4000);
BEGIN
   V_CHAR := ' '||CHR(1)||CHR(2)||CHR(3)|| CHR(4)||CHR(5)||CHR(6)||CHR(7)||CHR(8)||CHR(9)||CHR(10)||CHR(11)||CHR(12)||
             CHR(13)||CHR(14)||CHR(15)|| CHR(16)||CHR(17)||CHR(18)||CHR(19)||CHR(20)||CHR(21)||CHR(22)||CHR(23)||
             CHR(24)||CHR(25)||CHR(26)||CHR(27)|| CHR(28)||CHR(29)||CHR(30)||CHR(31)||CHR(127)||CHR(141)||CHR(143)||
             CHR(144)||CHR(157)||CASE WHEN P_RETIRA_PIPE = 'S' THEN CHR(124) ELSE '' END;

   SELECT TRIM(REPLACE(TRANSLATE(P_TEXTO,V_CHAR,' '),'  ',' '))
     INTO V_TEXTO
     FROM DUAL;
  
   RETURN(V_TEXTO);
END;