Just a quick check, is it possible to replace all the occurrences with a single select statement. If not, we plan to write a function to do this replace.
Sample string
select '#col1:val1@, #col2:val2@, #col3:val3@, #col4:val4@, #col5:val5@' str from dual
Expected output
str
---
col1 val1, col2 val2, col3 val3, col4 val4, col5 val5
Code so far
with test_table as
(Select '#col1:val1@, #col2:val2@, #col3:val3@, #col4:val4@, #col5:val5@' str from dual)
select level "occurrence", REGEXP_substr(str, '#(.*?):', 1, level, 'in', 1) "column", REGEXP_substr(str, ':(.*?)@', 1, level, 'in', 1) "value"
from test_table
CONNECT BY REGEXP_COUNT(str, '#.+?:.+?@') >= level
Additional Details
- String pattern is fixed and known beforehand.
- Occurrence of the given pattern is dynamic, may have any number of [column:value] pairs - they are actually [table column:alias] set.
- I have trimmed the sample string for simplicity, however it contains additional details (table joins, where clause etc.), so we would need to replace all the occurrences. It’s actually a select statement.