ORACLE:SQL REGEXP_SUBSTR,它返回第3个分号后的值以及值以D开头的管道之前
示例:
column value: 'D:5:testps:12345|blah blah/blah'
预期值:12345
正则表达式,它将过滤以D开头并在第3个分号后和管道之前返回值的值
答案 0 :(得分: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
答案 1 :(得分:0)
您可以使用regex_replace
:
select case when col like 'D%'
then regexp_replace(col, '^([^:]*:){3}(\d+)\|.*', '\2') num
end
from t;
产地:
12345
如果col不以D
开头,它将产生null