G-7430
πWarning
Try to use no more than one RETURN statement within a function.
Reason
A function should have a single point of entry as well as a single exit-point.
Examples
Non-Compliant Example
create or replace package body my_package is
function my_function(in_value in pls_integer) return boolean
deterministic
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;
/ | Line | Column | Message |
|---|---|---|
| 8 | 10 |
Compliant Solution - β
β
β
ββ
create or replace package body my_package is
function my_function(in_value in pls_integer) return boolean
deterministic
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;
/ Compliant Solution - β
β
β
β
β
create or replace package body my_package is
function my_function(in_value in pls_integer) return boolean
deterministic
is
co_yes constant pls_integer := 1;
begin
return in_value = co_yes;
end my_function;
end my_package;
/ References
- same as Trivadis G-7430
