Oracle:替换字符串中的非数字字符 [英] Oracle: Replacing non-numeric chars in a string

查看:1504
本文介绍了Oracle:替换字符串中的非数字字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据库中有一个字段,用户在其中保存了自由格式的电话号码.结果,数据具有各种不同的格式:

I have a field in my database where users have saved free-form telephone numbers. As a result, the data has all sorts of different formatting:

  • (区域)nnn-nnnn
  • area-nnn-nnnn
  • area.nnn.nnnn

我想去除所有非数字字符并只存储数字,但是我找不到一种简单的方法来做到这一点.是否可以不为每个字符使用一个REPLACE?

I would like to strip out all the non-numeric characters and just store the digits, but I can't find a simple way to do this. Is it possible without using one REPLACE for each char?

推荐答案

您可以使用

You can use REGEXP_REPLACE since Oracle 10:

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

此示例返回349471234562013.

其他语法包括:

  • POSIX字符类:

  • POSIX character classes:

'[^[:digit:]]+'

  • 受Perl影响的扩展(自Oracle 11开始):

  • Perl-influenced extensions (since Oracle 11):

    '\D+'
    

  • 这篇关于Oracle:替换字符串中的非数字字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆