The issue arises from the plsql_optimize_level
parameter, which controls how Oracle optimizes the SQL statements generated by the PL/SQL compiler. When this parameter is set to 1
, the optimizer leaves the SQL statement as it was written in the code, without reordering or reorganizing the clauses.
In the case of a function with an if
statement that returns immediately after its condition is met, setting plsql_optimize_level = 1
ensures that the entire if
block remains together in the coverage report. This is because Oracle doesn’t reorder the statements based on their semantic meaning and optimizes them according to their execution order.
However, when plsql_optimize_level = 2
, the optimizer reorders the statements to minimize the number of branches and joins, which can result in a different sequence of blocks being executed during coverage collection. As a result, the optimizer may split the original function into two separate blocks, resulting in neither block being reported as covered.
Setting plsql_optimize_level = 1
ensures that the entire code is treated as a single unit, so if you have a long chain of operations that need to be tested together (and not independently), use this value.
Last modified on 2025-01-15