Home

cursor%NOTFOUND should be used instead of NOT cursor%FOUND

Rule description

  • cursor%NOTFOUND should be used instead of NOT cursor%FOUND

 

Non-compliant Code Example

DECLARE
CURSOR cur_dept (departmentId INTEGER) RETURN departments%ROWTYPE IS  -- Define cur_dept,
    SELECT * FROM departments              -- repeating return type
    WHERE department_id = departmentId;	
	
BEGIN
  OPEN cur_dept;
  FETCH cur_dept INTO temp1;
  IF NOT cur_dept%FOUND THEN  --Non compliant code (Cursor is using "NOT cursor%FOUND" instead of "cursor%NOTFOUND" )
    DBMS_OUTPUT.PUT_LINE('Not Found !!');
  ELSE
    DBMS_OUTPUT.PUT_LINE('Department Found: ' || temp1);
  END IF;
  CLOSE cur_dept;
END;

Compliant Code Example

DECLARE
CURSOR cur_dept (departmentId INTEGER) RETURN departments%ROWTYPE IS  -- Define cur_dept,
    SELECT * FROM departments              -- repeating return type
    WHERE department_id = departmentId;
	
BEGIN
  OPEN cur_dept;
  FETCH cur_dept INTO temp1;
  IF cur_dept%NOTFOUND THEN  --Compliant code (Cursor is using "cursor%NOTFOUND" )
    DBMS_OUTPUT.PUT_LINE('Not Found !!');
  ELSE
    DBMS_OUTPUT.PUT_LINE('Department Found: ' || temp1);
  END IF;
  CLOSE cur_dept;
END;
Visual Expert 2020
 VEPLSQLRULE115