Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Help on Removing "Junk" Characters
Here is one approach using translate, there certainly may be other
approaches.
The keep list defined here is a-z, A-Z, 0-9, and ' ' (space). This
will not trim repeated spaces
As always, test before using: Credit goes to asktom.oracle.com for the
select chr(level) l_char, level lvl from dual connect by level<=255 syntax.
create or replace function keep_chars return string
as
keep_chars varchar2(255);
begin
keep_chars := '';
for x in ( select l_char from (select
chr(level) l_char, level lvl from dual connect by level<=255) where lvl between 48 and 57 or lvl between 65 and 90 or lvl between 97 and 122 or lvl = 32 ) loop keep_chars := keep_chars || x.l_char;
create or replace function drop_chars return string
as
drop_chars varchar2(255);
begin
drop_chars := '';
for x in ( select l_char from (select
chr(level) l_char, level lvl from dual connect by level<=255) where not( lvl between 48 and 57 or lvl between 65 and 90 or lvl between 97 and 122 or lvl = 32) ) loop drop_chars := drop_chars || x.l_char;
--drop table test1;
create table test1 as
select 'Pericles Comidas cl?cas Guillermo Fern?ez ' text from dual
union all select 'Queen Cozinha L?cia Carvalho ' from dual union all select 'Supr?s delices ' from dual union all select 'START' || drop_chars || 'END' from dual union all select 'START' || reverse(drop_chars) || 'END' from dualunion all select keep_chars from dual;
select translate(text, keep_chars || drop_chars , keep_chars) translated_text from test1;Received on Tue Oct 18 2005 - 11:20:25 CDT
![]() |
![]() |