tags:

views:

119

answers:

2

Can anybody please tell me what is the use of %NOTFOUND operator?

We can use "NOT %FOUND" in cursor also. It will perform same functionality.

+1  A: 

Sometimes there's just more than one way to do a thing. Most developers tend to use %NOTFOUND (at least in my experience).

Edit

I don't know why the devisers of the PL/SQL language gave us %NOTFOUND. I'll try to remember to ask Bryn Llewellyn the next time I see him. But my guess is, they just thought it would be useful. In coding, as in other forms of writing, we should always try to express ourselves positively, because positivity expresses our intent more clearly. That is,

exit when c1%notfound;

is clearer then

exit when not c1%found;

But perhaps it is just a matter of taste.

However, the situation with %ISOPEN is a lot easier to answer. We have no use for a %ISNOTOPEN operator. There are two times when we would want to use %ISOPEN. The first is before we open a cursor when there is a possibility that the cursor may already be open (this ought to be a very rare circumstance). The other is when we may need to close an opened cursor, say in a EXCEPTIONS block. In both situations we are interested in knowing that the cursor is OPEN. There is no value in testing whether the cursor is NOT OPEN.

APC
Thanx for your ans. However, why it is only for %FOUND and not for %ISOPEN? I want to know is there any other reason behind it
Pravin Satav
+1  A: 

PL/SQL, like related languages Ada and SQL, tends to favour a somewhat English-like structure (e.g. did you know that the COMMIT command has an optional "WORK" parameter, which does absolutely nothing?)

Being able to read the code out loud in a natural way is not a bad feature - i.e. saying "Exit when the cursor c1 is not found" sounds a bit more natural than "Exit when not the cursor is found"...

Jeffrey Kemp
Very interesting about the "WORK" parameter. I have found the English-like structure very helpful when reviewing code with Business Analysis types that don't work with code all day.
caddis