views:

100

answers:

3

Hi all!

Maybe this sounds a little bit crazy, but I need to come up with a query to retrieve only letters out of an alphanumeric field.

For example:

TABLE
1234ADD
3901AC
1812OPA
82711AUU

RESULTS EXPECTED
ADD
AC
OPA
AUU

Thank you!

+2  A: 
SELECT  REGEXP_REPLACE('1234ADD 3901AC 1812OPA 82711AUU', '[0-9]', '')
FROM    dual
Quassnoi
+4  A: 

Looks like you only want to remove numbers. You can use REGEXP_REPLACE for that in 10g or 11g:

SELECT REGEXP_REPLACE( your_column, '[0-9]*', '' ) FROM your_table;
Peter Lang
Thanks Peter, worked perfectly!
danboh
+2  A: 

Try

SELECT TRANSLATE('1234ADD 3901AC 1812OPA 82711AUU', 'A1234567890', 'A') FROM dual;

and in general see: http://www.psoug.org/reference/translate_replace.html

p.marino
Didn't work, maybe because of the Oracle version?
danboh
I wrote this a bit hurriedly and don't have an Oracle instance handy to test it, sorry. This is why I added the link...
p.marino
corrected. If the third parameter to TRANSLATE is NULL it always returns NULL.
Jeffrey Kemp