Srikant, October 01, 2016 - 2:13 pm UTC
Thanks Connor!
It's a good idea to find out the culprit rows first and then check later which conditions failed.
Related question
Srikant, October 02, 2016 - 4:44 am UTC
Hi Connor,
I wanted to ask one related question.
Can we create "generic" dynamic query for validation which will work for all the checks (rules)? I mean reading rule from metadata table and creating query based on that.
Suppose that if new rules are added or deleted from the meta data table then the procudure is able to handle that?
Regards,
Srikant
October 02, 2016 - 8:23 am UTC
Yes, that is what I mean. You would read from the metadata to produce a validation SQL, which would then be run via (say) 'execute immediate'. So as the rules change over time, you dont need to alter the code.
follow up
A reader, October 02, 2016 - 11:21 am UTC
Hi Connor,
Thanks for replying!
I had suggested the below metadata table structure to my team, but they rejected this approach saying that I am storing (RULE column) the entire where clause inside the table (hardcoding).
To which my response to them was "how will I build dynamic query, without hardcoding I will have to use multiple IFs clauses and the procedure will be no longer be dynamic".
My suggested structure (building sql statement is easy as I have to concatinate):
Table Field RULE Column_Length Primary_Key
-------------------------------------------------------------------
Sales Order OEDER IS NULL 30 Y
Sales Name LENGTH(NAME)=40 40 N
Sales Amount INTEGER 76 N
Product ID ID IS NULL 10 Y
Their Structure (building sql is difficult):
Table Field RULE Column_Length Primary_Key
-------------------------------------------------------------------
Sales Order NOT_NULL 30 Y
Sales Name LENGTH 40 N
Sales Amount INTEGER 76 N
Product ID NOT_NULL 10 Y
Regards,
Srikant
October 03, 2016 - 12:08 am UTC
There is perhaps a risk element in having full predicate clauses (as per your table) because someone could do some sql injection.
But either does not seem too hard to generate SQL from ?
select
case
when rule = 'NOT_NULL' then ' or ('||field||' is null )'
when rule = 'LENGTH' then ' or (length('||field||') != '||column_length||' )'
etc