2017-01-17 37 views
-1

比方說,在表的某些字段中,我有以下字符串:a=A#abc=Y#sps=Y# 。 我想查詢的a並獲得A與此查詢:使用REGEXP_SUBSTR從字符串提取屬性值

select UPPER(REGEXP_SUBSTR(REGEXP_SUBSTR(
    'a=Y#abc=Y#sps=Y#' , 
    'a\=([^#]+)#?'), '[[:alpha:]]')) from dual; 

我得到:

a 
--------------- 
N 
1 row selected 
+0

歡迎來到Stackoverflow!爲了充分利用網站,提出一些好問題很重要。有關提問的指南,請訪問:http://stackoverflow.com/help/how-to-ask –

回答

0

您可能需要一個REGEXP_SUBSTR:

SQL> select regexp_substr(s,'(nonExcludableInd=)([^#]*)', 1, 1, '', 2) 
    2 from (
    3   select 'nonExcludableInd=ABCD#includePrstInd=Y#cpeInd=Y#' as s from dual 
    4  ); 

REGE 
---- 
ABCD 

沒有正則表達式的溶液可以是:

select substr(s, startPosition, instr(s, '#', startPosition) - startPosition) 
from ( 
     select instr(s,'nonExcludableInd=')+17 as startPosition, s 
     from (
       select 'nonExcludableInd=A#includePrstInd=Y#cpeInd=Y#' as s from dual 
      ) 
    ) 
+0

謝謝。它的工作,但假設我有多個字符來代替'A',我需要提取所有,然後? – Mishti

+0

這適用於通用字符串,不僅是'A'。 – Aleksej

+0

沒有正則表達式的人只能提取'A',但只有一個人使用regexp_substr。我需要regexp_substr的解決方案。 – Mishti