Oracle 12cR1
I have a column with lengthy strings like below
:Key1:Value1:Key2:Value2:Key3:Value3:Key4...…..
The keys are unique numbers. The values are any string value which can even be a number same as any other key. If I give a key i must get its corresponding value. For example,
lengthy_str_col := ':101:abc:12:43:43:101.4:4:bus'
For getting the value for the key, 43, I tried the following.
SELECT REGEXP_SUBSTR(lengthy_str_col,'(:([^:])+)(:[^:]+)') FROM DUAL;
This gives me the first key-value pair ':1:abc'
. Now as I know that 43 is the third key, I used
SELECT REGEXP_SUBSTR(lengthy_str_col,'(:([^:])+)(:[^:]+)', 1, 3, 'i', 4) FROM DUAL;
to get the value 101.4
for the key 43
.
But a required key can be at any random position. Is there a way to get the value for any given key?