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;
/Issues
| 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