Like the rule S1172 for procedure and function, I suggest the following rule for Cursors
description of the Rule. Unused cursor parameters are misleading. Whatever the values passed to such parameters, the behavior will be the same.
snippet of Noncompliant Code (pp_status is not used)
cursor c_list_emp(pp_country varchar2, pp_status varchar2) is
select e.employee_code,
p.first_name,
p.last_name,
e.country
from persons p,
join employee_list e on e.person_id = p.person_id
where e.country = pp_country;
snippet of Compilant Code (fixing the above noncompliant code)
cursor c_list_emp(pp_country varchar2, pp_status varchar2) is
select e.employee_code,
p.first_name,
p.last_name,
e.country
from persons p,
join employee_list e on e.person_id = p.person_id
where e.country = pp_country
and e.status_code = pp_status; -- use the parameter
or
cursor c_list_emp(pp_country varchar2) is -- Remove the parameter
select e.employee_code,
p.first_name,
p.last_name,
e.country
from persons p,
join employee_list e on e.person_id = p.person_id
where e.country = pp_country;
exceptions to the Noncompliant Code: None
external references and/or language specifications
Thank you for suggesting this rule. It makes perfect sense. I created the corresponding RSPEC-6048. Let me know if you see any problem with it.
There is one thing I would like to clarify before this rule is implemented. I see that some implementations of S1172 raise one issue per function which has unused parameters, whereas other versions raise one issue per unused parameter. I think we should decide once and for all which approach is preferred and stick to it. I’ll ask some people around and see if there is a consensus. If you have an opinion don’t hesitate to share it here.
I would prefer one issue per unused parameter, then it will be easiest to remove the unused parameter.
With one issue for one to n unused parameters we will have to check each parameter to know which one is unused.
(we don’t have always small cursor as you can imagine )
The main difference is that you won’t have to close many issues if in one case there is a good reason to have unused parameters. For PL/SQL I don’t see why this would happen but it happens for other programming languages.