0

ORACLE:SQL REGEXP_SUBSTR 返回第三个分号之后和值以 D 开头的管道之前的列值

例子:

column value: 'D:5:testps:12345|blah blah/blah'

期望值:12345

正则表达式将过滤以 D 开头的值并在第三个分号之后和管道之前返回值

4

2 回答 2

2
select column_value,
   regexp_substr(column_value, '([^:]*:){3}([^|]*)\|', 1, 1, null, 2) as str
from (
       select 'D:5:testps:12345|blah blah/blah' as column_value from dual union all
       select 'XD:5:testps:12345|blahblah/blah' as column_value from dual
     )
where column_value like 'D%'
;

COLUMN_VALUE                      STR
-------------------------------   -----
D:5:testps:12345|blah blah/blah   12345
于 2017-02-24T16:34:22.857 回答
0

您可以使用regex_replace

select case when col like 'D%' 
            then regexp_replace(col, '^([^:]*:){3}(\d+)\|.*', '\2') num
       end
from t;

生产:

12345

如果 col 不以 D 开头,它将产生 null

于 2017-02-24T16:38:18.373 回答