Consider a table with 3 columns
Value1 operator value2
abc = xyz
1 != 2
5 > 8
9 <= 11
xyz is not Null
{null val} is null
I want to write a genric function which returns the validated result either true or false
by validating value1 with value2 using the operator
or check value1 in case of ‘is null’ and ‘is not null’ operators (Last two cases)
You could do something like this with dynamic SQL (note that in reality you’d need to add a bunch of logic to prevent SQL injection attacks)
Since you are storing the data in a table, that implies that each column is a
VARCHAR2. My guess, though, is that you don’t always want to use string comparison semantics. For example, the string ‘9’ is greater than the string ’11’ while the number 9 is less than the number 11. If you want to use something other than string comparison semantics, you’d need to add code that inspected the parameters and applied whatever logic you would like to determine what comparison semantics you want to apply and then generated the appropriate dynamic SQL statement.I would strongly question the wisdom of the requirement, however. First off, it makes little sense from a data model standpoint to store numeric data in a
VARCHAR2column– when you find yourself trying to mix string and numeric data in the same column, you’ve almost always made a data model mistake. I would also be hard-pressed to imagine what business problem you are trying to solve that would involve this sort of dynamic function– it seems likely that there is a better way to solve whatever problem you are attempting to solve.