Oracle: Replacing non-numeric chars in a string

You can use REGEXP_REPLACE since Oracle 10:

SELECT REGEXP_REPLACE('+34 (947) 123 456 ext. 2013', '[^0-9]+', '')
FROM DUAL

This example returns 349471234562013.

Alternative syntaxes include:

  • POSIX character classes:

    '[^[:digit:]]+'
    
  • Perl-influenced extensions (since Oracle 11):

    '\D+'
    

Leave a Comment

File not found.