2017-02-24 61 views

回答

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 
0

您可以使用regex_replace

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

產地:

12345 

它產生的空當山坳不d開始

+0

什麼將這個回報,做一個字符串不是以D開頭? (我認爲OP不希望返回任何東西 - 甚至不是NULL。)NULL仍然是從D開始的字符串的有效返回! – mathguy

相關問題