In answer to your question there is no "default" value. %NOTFOUND
is a "variable" that is instantiated upon the opening of a cursor. The value at that point is null; I guess you could call this the default if you wanted. After the first fetch of a cursor the value will either be true of false depending on whether any rows were returned. After the cursor is closed the "variable" no longer exists.
To quote from the 11gr2 documentation:
%NOTFOUND (the logical opposite of %FOUND) returns:
NULL after the explicit cursor is opened but before the first fetch
FALSE if the most recent fetch from the explicit cursor returned a row
TRUE otherwise
The 10g documentation has a useful table that demonstrates this
+----------------+--------+--------------+
| stage | when | return value |
+----------------+--------+--------------+
| open | before | exception |
| | after | null |
| first fetch | before | null |
| | after | false |
| next fetch(es) | before | false |
| | after | false |
| last fetch | before | false |
| | after | true |
| close | before | true |
| | after | exception |
+----------------+--------+--------------+
However, there does appear to be a direct contradiction in the Oracle documentation. The 11g documentation also has something similar to what you've described. The wording of which seems to directly contradict the above assertion
Note: In Example 6-16, if FETCH never fetches a row, then c1%NOTFOUND
is always NULL and the loop is never exited. To prevent infinite
looping, use this EXIT statement instead: EXIT WHEN c1%NOTFOUND OR
(c1%NOTFOUND IS NULL);
The 10g documentation is more explicit and slightly differently worded. This isn't a direct contradiction
Before the first fetch, %NOTFOUND evaluates to NULL. If FETCH never
executes successfully, the EXIT WHEN condition is never TRUE and the
loop is never exited. To be safe, you might want to use the following
EXIT statement instead:
EXIT WHEN c1%NOTFOUND OR c1%NOTFOUND IS NULL;
In general I would say that it's wise to trust the documentation and write EXIT WHEN c1%NOTFOUND OR c1%NOTFOUND IS NULL
.
I don't know in what situations a fetch would not execute successfully; I've asked the question. If the fetch never returns a value due to locking etc then you'll never reach the part of the code to determine whether it failed or not.
René Nyffenegger has some code on his blog that is a good explanation of how %NOTFOUND
works.