G-8310 value_error good_example
PrzemekFilipiak opened this issue · comments
Hi,
Changing variable declarion to default will raise "value_error" if in_dept_name := null
create or replace package body department_api is
function dept_by_name( -- NOSONAR: non-deterministic
in_dept_name in departments.department_name%type
)
return departments%rowtype is
-- co_dept_name constant departments.department_name%type not null := in_dept_name;
co_dept_name departments.department_name%type not null default 'example department_name';
r_return departments%rowtype;
begin
-- get the department by name
<>
begin
co_dept_name := in_dept_name; -- if in_dept_name := null, will raise "value_error"
select *
into r_return
from departments
where department_name = co_dept_name;
return r_return;
exception
when no_data_found then
return null;
when too_many_rows then
raise;
when value_error then
handle_error;
end trap;
end dept_by_name;
end department_api;
/
Could you please elaborate how your change of the good example code in G-8310 is related to this guideline?
What kind of change are you suggesting?
Regarding your code change. You changed a constant to a variable with a default value. If you would like to accept a null value you have to get rid of the NOT NULL
in the declaration. However, this is not related to the G-8310 IMO.
In your example, you are assigning the parameter to a variable in the body and not in the declare section. Hence you are not following the guideline G-8310.
G-8310: Always validate input parameter size by assigning the parameter to a size limited variable in the declaration section of program unit.