G-2135
🆓Warning
Avoid assigning values to local variables that are not used by a subsequent statement.
Reason
Expending resources calculating and assigning values to a local variable and never use the value subsequently is at best a waste, at worst indicative of a mistake that leads to a bug.
Example
Non-Compliant Example
create or replace package body my_package is procedure my_proc is co_employee_id constant employees.employee_id%type := 1042; co_hello constant type_up.text := 'Hello, '; l_last_name employees.last_name%type; l_message types_up.text; begin select emp.last_name into l_last_name from employees emp where emp.employee_id = co_employee_id; l_message := co_hello || l_last_name; exception when no_data_found then null; -- handle_no_data_found; when too_many_rows then null; -- handle_too_many_rows; end my_proc; end my_package; /
Issues
Line | Column | Message |
---|---|---|
13 | 7 |
★★★★★
Compliant Solution -
create or replace package body my_package is procedure my_proc is co_employee_id constant employees.employee_id%type := 1042; co_hello constant type_up.text := 'Hello, '; l_last_name employees.last_name%type; l_message types_up.text; begin select emp.last_name into l_last_name from employees emp where emp.employee_id = co_employee_id; l_message := co_hello || l_last_name; message_api.send_message(l_message); exception when no_data_found then null; -- handle_no_data_found; when too_many_rows then null; -- handle_too_many_rows; end my_proc; end my_package; /
References
- same as plsql:S1854
- same as Trivadis G-2135