2017-01-17 38 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