Interest Ask! Just wanted to add a few things.
For me, the real problem depends on IS_OPEN to determine if the cursor is valid or not. Oracle can throw INVALID_CURSOR for many reasons, and it is possible that the "open" cursor is invalid. It seems reasonable to assume that the open cursor must be valid (and therefore we can extract from it or perform other operations, for example, a simple close), but this is not necessary.
For example, you cannot use cursor variables in remote procedure calls (via dblinks). The same example, even using the Alex workaround, will fail if open was called on an instance of 1 db, and fetching on another (if nested_test, any version, was defined on db_A and then called from db_B). However, the test for ISOPEN will still return TRUE, but the attempt to use the cursor (fetch) will fail.
INVALID_CURSOR may be raised for other reasons (for example, go beyond the maximum open cursors or sometimes open the cursor and wait a while before trying to use it).
All that said, there is no test "ISVALID", which I know. Imo's best approach is to open, select, and close cursors within the same program or subroutine. Creating a procedure whose responsibility is to simply OPEN, the cursor is a bit strange for me (but I'm sure there is some reason), and can cause difficulties to explain the problems (like this one). If you must have another program that opens the cursor for you, you might want to enter code that extracts and ultimately closes the cursor in an anonymous block and catches the INVALID_CURSOR exception.
Just my wanderings; -)
tbone
source share