I have a WARNINGS_INFO table that contains some info on a specific warning message, such as it’s code and level, and a string that describes how to print the output message.
ID | CODE | LEVEL | STR_FORMAT
------|----------------|-------|----------------------------------------------
5 | attrib_missing | 3 | On cell $R:$C, attribute $ATTRIB not found
Let’s assume I have a table GENERATED_WARNINGS with all the warnings generated from a SQL batch:
WARN_ID | WARN_ROW_ID
-----------|---------------
5 | 32
Also, I have another table with the columns R, C and ATTRIB and obviously a ROW_ID primary key column which WARN_ROW_ID refers to.
Is there a way in SQL to dynamically trasduce the STR_FORMAT string to a string with the data from the columns of the last table?
Here’s one stab at it using the Oracle
REPLACE()function: http://www.sqlfiddle.com/#!4/7d3c4/3This requires a nested call to
REPLACEfor each $variable in your warning message, so isn’t general purpose. For this kind of thing I do not think you should do the variable replacement in SQL. Extract the warning message, and the values for $R, $C, $ATTRIB, etc and do the variable substitution using a templating library like Velocity or FreeMarker.Given DDL:
The following query will do the parameter replacement:
The output from this will be: “On cell 42:99 attribute FOOBAR not found”