ORA-01000: maximum open cursors exceeded

来源:互联网 发布:网络常用端口号 编辑:程序博客网 时间:2024/05/22 12:33

 

 

 

1. How to fix

 

 

2. Why 

Cursor

http://en.wikipedia.org/wiki/Cursor_(databases)

 

In database packages, a cursor comprises a control structure for the successive traversal (and potential processing) of records in a result set.

Cursors provide a mechanism by which a database client iterates over the records in a database. Using cursors, the client can get, put, and delete database records. Database programmers use cursors for processing individual rows returned by the database system for a query.

 

Most of the times, set based operations can be used instead of cursors.

Fetching a row from the cursor may result in a network round trip each time. This uses much more network bandwidth than would ordinarily be needed for the execution of a single SQL statement like DELETE. Repeated network round trips can severely impact the speed of the operation using the cursor. Some DBMSs try to reduce this impact by using block fetch. Block fetch implies that multiple rows are sent together from the server to the client. The client stores a whole block of rows in a local buffer and retrieves the rows from there until that buffer is exhausted.

 

 

 

http://www.oracle.com/technology/oramag/oracle/08-nov/o68plsql.html

It’s important to know when not to use cursor FOR loops.

 

http://soft.buaa.edu.cn/oracle/bookshelf/Oreilly/prog2/ch09_05.htm

http://www.exforsys.com/tutorials/oracle-9i/oracle-cursors.html

http://www.geekinterview.com/question_details/2515

 

PL/SQL declares a cursor implicitly for all SQL data manipulation statements, including quries that return only one row. However,queries that return more than one row you must declare an explicit cursor or use a cursor FOR loop.
Explicit cursor is a cursor in which the cursor name is explicitly assigned to a SELECT statement via the CURSOR...IS statement. An implicit cursor is used for all SQL statements Declare, Open, Fetch, Close. An explicit cursors are used to process multirow SELECT statements An implicit cursor is used to process INSERT, UPDATE, DELETE and single row SELECT. .INTO statements.

 

 

3. Mysql has such problem ?

If do not close PreparedStatement/ResultSet in a Loop(For oracle, you must close statement, while for mysql both of them are ok), OOM error will be thrown.

 

 

 4. Statck overflow

http://stackoverflow.com/questions/103938/resultset-not-closed-when-connection-closed


在与DB打交道时,有几种资源
1. connection (server/client)

2. cursor  (server)

3. memory (server/client)

4. cpu (server)

其中java中的ResultSet , Statement 会影响cursor和memory,而sql语句本身会影响server端的cpu.

最后Connection不用说,一般采用connection pool来管理







原创粉丝点击