I am trying to run a vanilla regexp_replace, except the replacement string is dynamically selected using the backreference value.
To give a little more context, I have (say in two columns of the same table, for simplifying things) two strings. The first one contains placeholders like {1}, {2} as part of the string literal itself; which need to be replaced by the corresponding subfields of the second string (after tokenizing it with some constant delimiter, say '|').
So, if we have:
Str1 = 'The quick brown {1} jumps over the lazy {2}.'
Str2 = 'fox|dog'
We need the result as... I'm sure you get the point.
In an ideal world, Oracle (11g Enterprise 64-bit) would let me do this:
with x as (select 'The quick brown {1} jumps over the lazy {2}.' col1, 'fox|dog' col2 from dual)
select regexp_replace(x.col1, '({[0-9]+})', regexp_substr(x.col2,'[^|]+',1,'\1')) as result
from x
However, the second regexp_substr does not recognize the backreference from the outer regexp_replace call and throws an ORA-17222:invalid number.
I don't want to create a stored procedure or a function, as my business case is to create a (possibly materialized) view which will contain this data. I'd much rather there'd be a one-liner that could do this.
Looking at various forums, Oracle may not support this backreference passing, so the question title may be a bit misleading - if you could point me to towards another alternative (without resorting to other DDLs) that'd be just as well. I'm experienced in programming but not in Oracle itself, so please be gentle!
Some browsing has shown people tend to use obscure things like MODEL clauses and xmltables (haven't heard of them before today) for complex regexp puzzles, but I think there may be something awkwardly simple that I'm missing.