0

I have a multi-valued column , MISC_CONTENT with the following string in the column:

amount = 7995 ;channel = SXXXN21 ;group_header = NPS099 ;currency = EUR

How can retrieve the value NPS099 by lookup with group_header?

user2102665
  • 429
  • 2
  • 11
  • 26
  • use the SQL LIKE operator – jdigital Nov 04 '19 at 03:35
  • LIKE doesn't work in multi-valued, and the length value/sequence of group_header is random – user2102665 Nov 04 '19 at 03:39
  • 1
    You said _How can retrieve the value NPS099 by lookup with group_header?_ but it sounds like you're asking how to retrieve the value associated with `group_header`. if so, the regexp_substr answer below from @TimBiegeleisen looks like a reasonable approach – jdigital Nov 04 '19 at 03:53

1 Answers1

0

We can try using REGEXP_SUBSTR:

WITH yourTable AS (
    SELECT 'amount = 7995 ;channel = SXXXN21 ;group_header = NPS099 ;currency = EUR' AS col FROM dual
)

SELECT
    REGEXP_SUBSTR(col, '(^|\s|;)group_header = (.*?)\s*(;|$)', 1,1,NULL,2)
FROM yourTable;
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360