Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: How can I convert strings efficiently?
Originally posted by Guido Konsolke
> Hello everyone,
>
> current environment: 8.1.7.0.0 Enterprise Edition.
>
> I've a little problem I can't solve nicely. I want
> to replace everything in a string with NULL
> that isn't a letter or a number.
>
> I try to avoid writing something like
> replace(replace(replace...))).
>
> I know there must be a better way, but can't
> figure it out since I don't code that much nowadays (or am to dumb).
> A quick search on google and asktom didn't satisfy me.
>
> If a nice person could give me a hint I would be grateful.
>
> Greetings,
> Guido
This double TRANSLATE will do it:
SQL> select translate( example,
2 'a'||translate( lower(example), 3 '#abcdefghijklmnopqrstuvwxyz0123456789', 4 '#'), 5 'a' 6 )
TRANSLATE(EXAMP
Probably requires some explanation:
SQL> select translate( lower(example),
2 '#abcdefghijklmnopqrstuvwxyz0123456789', 3 '#')
TRANSLATE(L
(The redundant translation of '#' to '#' is to prevent the 3rd argument from being NULL, which cocks everything up).
2) The outer translate takes the original string and translates any of
the non-alpha characters from step 1 into NULLs, i.e. removes them.
-- Posted via http://dbforums.comReceived on Wed Apr 02 2003 - 06:25:19 CST
![]() |
![]() |