Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to handle no_data_found in 'for c in .... loop' statement

MalinowyMay 31 2012 — edited May 31 2012
Hi,

I wonder how to handle no_data_found exception in 'for c in .... loop' loop statement.
In following code program does not go to exception block.
BEGIN
  FOR C IN
  (SELECT 'x' FROM DUAL WHERE 1=2)
  LOOP
    DBMS_OUTPUT.PUT_LINE('Here we go with some data');
  END LOOP;
EXCEPTION
WHEN NO_DATA_FOUND THEN
  DBMS_OUTPUT.PUT_LINE('No data');
END;
Do I need to use a variable or there is some cursor attribute.
I work on DB version 11.2.0.2.0.

Thank you,
Marcin
This post has been answered by Frank Kulash on May 31 2012
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 28 2012
Added on May 31 2012
7 comments
3,736 views