Raise no data found exception if cursor is empty : Fetch « Cursor « Oracle PL/SQL Tutorial






SQL>
SQL> DECLARE
  2     d VARCHAR2(1);
  3     no_data_found EXCEPTION;
  4
  5     CURSOR myCursor IS SELECT dummy FROM dual WHERE 1=2;
  6  BEGIN
  7     OPEN myCursor;
  8     FETCH myCursor INTO d;
  9
 10     IF d IS NULL
 11     THEN
 12        RAISE no_data_found;
 13     END IF;
 14  EXCEPTION
 15     WHEN no_data_found
 16     THEN
 17        DBMS_OUTPUT.PUT_LINE ('Trapped the error!?');
 18  END;
 19  /
Trapped the error!?

PL/SQL procedure successfully completed.

SQL>
SQL>








25.4.Fetch
25.4.1.Fetch data into PL/SQL table
25.4.2.Fetch cursor value into column type variable
25.4.3.Fetch cursor till cursorName%NOTFOUND
25.4.4.Using a simple UPDATE statement without locking for rows fetched from Cursors
25.4.5.To lock all the records while you're working on them. This is done using a SELECT FOR UPDATE command
25.4.6.Fetching Across Commits
25.4.7.Fetching Across Commits, Example 2
25.4.8.Populating a Record with FETCH INTO
25.4.9.cursor bulk
25.4.10.Compare the performance differences between row-at-a-time processing and bulk processing
25.4.11.Raise no data found exception if cursor is empty
25.4.12.Fetch cursor to three variables
25.4.13.Nested cursor open
25.4.14.Fetch cursor till notfound
25.4.15.Fetch cursor to table collection of row type
25.4.16.Fetch cursor value to three variables
25.4.17.Fetch row by row