Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will an implicit cursor ever fail to close in PL/SQL?

With PL/SQL will there ever be a situation, say in the case of an exception, where an implicit cursor will fail to close?

I understand that an implicit cursor is supposed to close itself after use, but just want to know if there's ever a situation where this might not be the case, and if this is possible, what kind of remediation will be a good idea.

like image 410
user2100452 Avatar asked Feb 22 '13 18:02

user2100452


People also ask

What are the drawbacks of implicit cursors in PL SQL?

Drawbacks of Implicit CursorsIt is more vulnerable to data errors. It gives you less programmatic control. Even if your query returns only a single row, you might still decide to use an explicit cursor. However, there is no explicit cursor for UPDATE, DELETE, and INSERT statements.

What happens if we dont close the cursor in Plsql?

If you declare a cursor in an anonymous block, procedure, or function, the cursor will automatically be closed when the execution of these objects end. However, you must explicitly close package-based cursors. Note that if you close a cursor that has not opened yet, Oracle will raise an INVALID_CURSOR exception.

What happens when you don't close the cursor in Oracle?

Comments. Yes, open cursors both consume some memory on their own, and also pin pieces of the btree into cache, which interferes with JE's ability to manage its cache. You should always close cursors promptly, and remember to do so in a finally statement to make sure you don't leak them if there is an exception.

Does cursor hold temporary results?

A cursor is a name or handle to a specific private SQL area. As shown in Figure 14-5, you can think of a cursor as a pointer on the client side and as a state on the server side. The result of a query is a result set and is pointed to by the cursor. It is stored in a temporary location, either in memory or on disk.


1 Answers

When COMMIT or ROLLBACK fails the cursor will not close automatically
It is recommended to use route bellow when using cursors:

-- before using the cursor
    IF your_cursor %ISOPEN THEN
         CLOSE your_cursor;
    END IF;
   OPEN your_cursor;

-- after using the cursor
         CLOSE your_cursor;
-- when exception
    IF your_cursor %ISOPEN THEN
         CLOSE your_cursor;
    END IF;
like image 116
Mohsen Heydari Avatar answered Oct 15 '22 12:10

Mohsen Heydari