• Sorry, I neglected to speak to your larger question of getting away from dynamic SQL. it looks like you have SQL fragments or conditions sitting in tables, like this

    SELECT rul.SQL_STATEMENT

    FROM APP_RULE rul

    LEFT JOIN APP_RULE_EXCEPTION exc

    ON rul.RULE_ID = exc.RULE_ID

    that you are bringing into variables and string for later execution. If that is how the system was designed to work then dynamic SQL is your only option unless you do a complete refactor of the data model to store rules differently and rewrite all the SQL to move everything to a declarative code-model.

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato