Skip to main content

Avoid functions with OUT parameters

ZPA rule for PL/SQL and Oracle SQL · FunctionWithOutParameter

A function is expected to compute a value from its arguments and return it. An OUT or IN OUT parameter gives it a second, hidden result: nothing in l_total := order_total(p_order, l_count) says that l_count changes. Such a function also cannot be called from SQL (ORA-06572).

This rule reports an OUT or IN OUT parameter of a function. Return the values together, as a record or an object, or turn the function into a procedure with only OUT parameters.

Examples​

Noncompliant Code Example
create function order_total(p_order number, p_lines out number) return number is -- Noncompliant
l_total number;
begin
select sum(amount), count(*) into l_total, p_lines from order_line where order_id = p_order;
return l_total;
end;
Compliant Solution
create procedure order_totals(p_order number, p_total out number, p_lines out number) is
begin
select sum(amount), count(*) into p_total, p_lines from order_line where order_id = p_order;
end;