Trim integer from a string Trim integer from a string oracle oracle

Trim integer from a string


I would use the translate function. The REGEXP functions in Oracle tend to be CPU hogs compared to the simpler text processing functions.

select translate(string, 'A1234567890', 'A')from t;

The "A" at the beginning of the second parameter, and matching A for the last parameter translates "A"s to "A"s, doing nothing, but without something in the third parameter string, ORACLE will return null.

EDIT Simple test case

SQL> create table t (string varchar2(100));Table created.SQL> insert into t values ('ABC01');1 row created.SQL> insert into t values ('ABCD02');1 row created.SQL> insert into t values ('AB5123');1 row created.SQL> insert into t values ('ABCDEFGHIJKLMNOPQRSTUVWXYZ'  2      || 'abcdefghijklmnopqrstuvwxyz1234567890');1 row created.SQL> insert into t values ('123AB456');1 row created.SQL> insert into t values ('!Whatever!1');1 row created.SQL> commit;Commit complete.SQL> select translate(string, 'A1234567890', 'A')  2  from t;TRANSLATE(STRING,'A1234567890','A')---------------------------------------------------ABCABCDABABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzAB!Whatever!6 rows selected.


select REGEXP_REPLACE(YourColumn, '[0-9]+', '') from YourTable

Take a look at this SQLFiddle: http://sqlfiddle.com/#!4/b8a83/1