Home

Unused local variables should be removed

Rule description

  • Unused local variables should be removed

 

Non-compliant Code Example

DECLARE
limit PLS_INTEGER := 100;               --Non compliant code (Unused local variable)
CURSOR cur_dept (departmentId INTEGER) RETURN departments%ROWTYPE IS 
    SELECT * FROM departments          
    WHERE department_id = departmentId;	
	
BEGIN
  OPEN cur_dept;
  FETCH cur_dept 
  BULK COLLECT INTO temp1;
  IF NOT cur_dept%FOUND THEN  
    DBMS_OUTPUT.PUT_LINE('Not Found !!');
  ELSE
    DBMS_OUTPUT.PUT_LINE('Department Found: ' || temp1);
  END IF;
  CLOSE cur_dept;
END;

Compliant Code Example

CURSOR cur_dept (departmentId INTEGER) RETURN departments%ROWTYPE IS     --Compliant code (Removed unused local variable)
    SELECT * FROM departments          
    WHERE department_id = departmentId;	
	
BEGIN
  OPEN cur_dept;
  FETCH cur_dept 
  BULK COLLECT INTO temp1;
  IF NOT cur_dept%FOUND THEN  
    DBMS_OUTPUT.PUT_LINE('Not Found !!');
  ELSE
    DBMS_OUTPUT.PUT_LINE('Department Found: ' || temp1);
  END IF;
  CLOSE cur_dept;
END;
Visual Expert 2020
 VEPLSQLRULE124