G-7420
🆓Warning
Always make the RETURN statement the last statement of your function.
Reason
The reader expects the return
statement to be the last statement of a function.
Example
Non-Compliant Example
create or replace package body my_package is function my_function( in_from in pls_integer ,in_to in pls_integer ) return pls_integer deterministic is l_ret pls_integer; begin l_ret := in_from; <<for_loop>> for i in in_from..in_to loop l_ret := l_ret + i; if i = in_to then return l_ret; end if; end loop for_loop; end my_function; end my_package; /
Issues
Line | Column | Message |
---|---|---|
16 | 13 |
★★★★★
Compliant Solution -
create or replace package body my_package is function my_function( in_from in pls_integer ,in_to in pls_integer ) return pls_integer deterministic is l_ret pls_integer; begin l_ret := in_from; <<for_loop>> for i in in_from..in_to loop l_ret := l_ret + i; end loop for_loop; return l_ret; end my_function; end my_package; /
References
- same as Trivadis G-7420