G-7430: Try to use no more than one RETURN statement within a function.
Major
Will have a medium/potential impact on the maintenance cost. Maintainability, Testability
Reason
A function should have a single point of entry as well as a single exit-point.
Example (bad)
1 2 3 4 5 6 7 8 9 10 11 12 | create or replace package body my_package is function my_function (in_value in pls_integer) return boolean is k_yes constant pls_integer := 1; begin if in_value = k_yes then return true; else return false; end if; end my_function; end my_package; / |
Example (better)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | create or replace package body my_package is function my_function (in_value in pls_integer) return boolean is k_yes constant pls_integer := 1; l_ret boolean; begin if in_value = k_yes then l_ret := true; else l_ret := false; end if; return l_ret; end my_function; end my_package; / |
Example (good)
1 2 3 4 5 6 7 8 | create or replace package body my_package is function my_function (in_value in pls_integer) return boolean is k_yes constant pls_integer := 1; begin return in_value = k_yes; end my_function; end my_package; / |