'Oracle : Use of CURSOR%FOUND in PL/SQL

I have a code as follows.

My question is - why do we need IF statement for CURSOR%FOUND ?

If no rows are found, that will trigger NO_DATA_FOUND condition and control will automatically go to the EXCEPTION block.

Correct ?

begin

OPEN l_cursor;
LOOP
  FETCH l_cursor into l_rec;
  
  if ( l_cursor%FOUND ) then
      do something
  else
      do_something_else;
  end if;
  
END LOOP;

CLOSE l_cursor

EXCEPTION
   WHEN no_data_found then
     ...
END;


Solution 1:[1]

OPEN l_cursor;
LOOP     
  FETCH l_cursor into l_rec;
  EXIT WHEN l_cursor%NOTFOUND;
  ...do something...
END LOOP;
CLOSE l_cursor;
EXCEPTION
   WHEN no_data_found then
     ...
END;

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1