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>