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)

CREATE OR REPLACE PACKAGE BODY my_package IS
   FUNCTION my_function (in_value IN PLS_INTEGER) RETURN BOOLEAN IS
      co_yes CONSTANT PLS_INTEGER := 1;
   BEGIN
      IF in_value = co_yes THEN
         RETURN TRUE;
      ELSE
         RETURN FALSE;
      END IF;
   END my_function;
END my_package;
/

Example (better)

CREATE OR REPLACE PACKAGE BODY my_package IS FUNCTION my_function (in_value IN PLS_INTEGER) RETURN BOOLEAN IS co_yes CONSTANT PLS_INTEGER := 1; l_ret BOOLEAN; BEGIN IF in_value = co_yes THEN l_ret := TRUE; ELSE l_ret := FALSE; END IF;

  RETURN l_ret;

END my_function; END my_package; /

Example (good)

CREATE OR REPLACE PACKAGE BODY my_package IS
   FUNCTION my_function (in_value IN PLS_INTEGER) RETURN BOOLEAN IS
      co_yes CONSTANT PLS_INTEGER := 1;
   BEGIN
      RETURN in_value = co_yes;
   END my_function;
END my_package;
/