G-7420: Always make the RETURN statement the last statement of your function.

Major

Maintainability

Reason

The reader expects the RETURN statement to be the last statement of a function.

Example (bad)

CREATE OR REPLACE PACKAGE BODY my_package IS
   FUNCTION my_function (in_from IN PLS_INTEGER
                       , in_to   IN PLS_INTEGER) RETURN PLS_INTEGER 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;
/

Example (good)

CREATE OR REPLACE PACKAGE BODY my_package IS
   FUNCTION my_function (in_from IN PLS_INTEGER
                       , in_to   IN PLS_INTEGER) RETURN PLS_INTEGER 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;
/