ORACLE:SQL REGEXP_SUBSTR 即 returns 在第 3 个分号之后和值以 D 开头的竖线之前的列值

ORACLE:SQL REGEXP_SUBSTR that returns the column value after 3rd semicolon and before the pipe whose value starts with D

ORACLE:SQL REGEXP_SUBSTR即returns第3个分号之后和值以D

开头的管道之前的列值

示例:

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

期望值:12345

正则表达式将过滤以 D 开头的值和 returns 在第 3 个分号之后和管道

之前的值
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

您可以使用 regex_replace:

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

生产:

12345

如果列不是以 D

开头,则返回 null