rules repository

G-2145

🆓
Error

Never self-assign a variable.

Reason

There is no reason to assign a variable to itself. It is either a redundant statement that should be removed, or it is a mistake where some other value was intended in the assignment.

Example

Non-Compliant Example

declare
   co_parallel_degree constant types_up.name%type := 'parallel_degree';
   l_function_result  pls_integer;
   l_parallel_degree  pls_integer;
begin
   l_function_result := maintenance.get_config(co_parallel_degree);
   if l_function_result is not null then
      l_parallel_degree := l_parallel_degree;
      do_something(l_parallel_degree);
   end if;
end;
/
Issues
LineColumnMessage
87Self-assigned variable.

Compliant Solution - ★★★★★

declare
   co_parallel_degree constant types_up.name%type := 'parallel_degree';
   l_function_result  pls_integer;
   l_parallel_degree  pls_integer;
begin
   l_function_result := maintenance.get_config(co_parallel_degree);
   if l_function_result is not null then
      l_parallel_degree := l_function_result;
      do_something(l_parallel_degree);
   end if;
end;
/

References