Erorr ORA-1000, maximum open cursors exceeded.
We are running a VC++ application on a Oracle 7.3 server and are
gettting this erorr. We increased the parameter from its default to 200.
But we would like to know how can we find out the noumber and
text of the opem cursors. ?
If i am right open cursors would be uncommited statements ?
Thanx
Charanjiv
No, open cursors would be cursors you OPENed but never closed or they would be cached cursors that plsql keeps open (if you are using lots of stored procedures, you'll see the cached cursors from these). Cursors stay open across commits normally.
You can see the cursors you have open (all open cursors in the database) by reviewing the dynamic performance view
v$open_cursors. You can use this to track down cursors you have opened in your application but have forgotten to close or to verify the cursors are being cached by plsql for you.
I keep my open cursors set at about 1,000. Cursor entries are aquired 64 at a time, regardless of the open cursor setting, so setting to a high number will not affect memory consumption for all clients -- just those that need it.
See also the documentation for "close_cached_open_cursors" in the server reference guide if you really want plsql to close cached cursors upon commit (this parameter is obsoleted in 8.1 -- a new algorithm is used and this is no longer needed). I don't recommend setting this but some people want to anyway.
followup to comment one belowwell, it varies by language.
in jdbc, preparedStatement.close() does it.
In pro*c EXEC SQL CLOSE CURSOR_NAME; does it.
In OCI -- there is an API call to close a statement
and so on.
followup to comment threeNo,
no it is not.
Open cursors are
not uncommitted statements. Open cursors are -- lo and behold -- cursors you have not closed.
If you are in JDBC and you let a statement handle go out of scope (don't have any idea what a loop might have to do with it except that I could use a loop to exhaust open cursors rapidly), you will have open cursors that you can no longer get to to close.
But the same would be true if you opened a file and didn't close it properly. Just consider a statement a file, eventually, when you are done and will never need that file again -- close it. Same with the cursors (statements). When you are done (and not before, if you might reuse it, don't close it) with the statement -- close it and you will not have this error.
This error is 100% caused by a programmer leaking cursors, if you replace the database statements with file opens, you would be running out of file descriptors -- same issue.
Do NOT close each query after it is executed, you should prepare a statement at most ONCE per program execution and then rebind/execute it over and over. If there is a chance that you will execute the statement again, keep it open (don't let it go out of scope!)
See
</code>
http://asktom.oracle.com/pls/asktom/f?p=100:11:::::P11_QUESTION_ID:1478004815829 <code>
for why the advice to close after each query is executed is potentially bad advice.