Skip to content
Advertisement

In Oracle SQL, replace variable number of placeholders with values from a second table

Table 1 has error messages with a variable number of numbered placeholders within squiggly brackets. I need to build the completed messsage with values from a 2nd table.

Table 1:

Table 2

The relationship between the tables is, of course, the error_id and placeholder/arg_seq_nbr values.

A correct result would be, for example: PODate BadData has an invalid time stamp format.

I have tried ‘with cte…’ and a couple things but can’t quite get it to work. I can only get it to return 8 rows (instead of 4) with each of those 8 rows containing the same arg_value in each placeholder.

Advertisement

Answer

If you have a maximum number of arguments, then one method would be:

An alternative to this approach would be a recursive CTE. But I think the above is simpler if it works in your case.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement