【问题标题】:Regex in oracle SQL - return all numbers in a string, comma-delimitedoracle SQL中的正则表达式-返回字符串中的所有数字,以逗号分隔
【发布时间】:2013-06-26 09:00:36
【问题描述】:

我的输入值是这样的:

Value:123 with subvalues:[134,135,136]

我只想从中提取所有数字,并在它们至少由一个非数字字符分隔时保持逗号分隔。我现在正在使用这个:

regexp_replace(message,  '[^[:digit:]]')

这会拉出数字,但显然甚至将这些数字之间的空格替换为空。我怎样才能得到结果:

123,134,135,136

【问题讨论】:

  • 老实说,听起来您正在做的事情应该在应用程序逻辑中解决,而不是在数据库中。

标签: sql regex oracle


【解决方案1】:
select
    regexp_replace(
        regexp_replace(
            'Value:123 with subvalues:[134,135,136]',
            '[^[:digit:]]+', ','),
        '^,+|,+$'
    ) as s
from dual;

结果:

s
---------------
123,134,135,136

【讨论】:

    猜你喜欢
    • 2020-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多