@@ -149,6 +149,7 @@ limitations under the License.
149149 - 9.1.6.4 [ Fetching Numbers and Dates as String] ( #fetchasstringhandling )
150150 - 9.1.6.5 [ Mapping Custom Types] ( #customtypehandling )
151151 - 9.1.7 [ Row Prefetching] ( #rowprefetching )
152+ - 9.2 [ Cursor Management] ( #cursors1000 )
15215310 . [ PL/SQL Execution] ( #plsqlexecution )
153154 - 10.1 [ PL/SQL Stored Procedures] ( #plsqlproc )
154155 - 10.2 [ PL/SQL Stored Functions] ( #plsqlfunc )
@@ -3810,6 +3811,82 @@ connection.execute(
38103811 });
38113812` ` `
38123813
3814+ ### <a name="cursors1000"></a> 9.2 Cursor Management
3815+
3816+ Developers starting out with Node have to get to grips with the
3817+ 'different' programming style of JavaScript that seems to cause
3818+ methods to be called when least expected! While you are still in the
3819+ initial hacking-around-with-node-oracledb phase you may sometimes
3820+ encounter the error *ORA-01000: maximum open cursors exceeded*. A
3821+ cursor is a "handle for the session-specific private SQL area that
3822+ holds a parsed SQL statement and other processing information".
3823+
3824+ Here are things to do when you see an *ORA-1000*:
3825+
3826+ - Avoid having too many incompletely processed statements open at one time:
3827+
3828+ - Make sure your application is handling connections and statements
3829+ in the order you expect.
3830+
3831+ - [Close ResultSets](https://github.com/oracle/node-oracledb/blob/master/doc/api.md#close) before
3832+ releasing the connection.
3833+
3834+ - If cursors are opened with ` DBMS_SQL .OPEN_CURSOR ()` in a PL/SQL
3835+ block, close them before the block returns - except for REF
3836+ CURSORs being passed back to node-oracledb.
3837+
3838+ - Choose the appropriate Statement Cache size. Node-oracledb has a
3839+ statement cache per connection. When node-oracledb internally
3840+ releases a statement it will be put into the statement cache of that
3841+ connection, and its cursor will remain open. This makes statement
3842+ re-execution very efficient.
3843+
3844+ The cache size is settable with the
3845+ [` oracle .stmtCacheSize ` ](https://github.com/oracle/node-oracledb/blob/master/doc/api.md#propdbstmtcachesize) attribute.
3846+ The size you choose will depend on your knowledge of the
3847+ locality of the statements, and of the resources available to the
3848+ application. Are statements re-executed? Will they still be in the
3849+ cache when they get executed? How many statements do you want to be
3850+ cached? In rare cases when statements are not re-executed, or are
3851+ likely not to be in the cache, you might even want to disable the
3852+ cache to eliminate its management overheads.
3853+
3854+ Incorrectly sizing the statement cache will reduce application
3855+ efficiency.
3856+
3857+ To help set the cache size, you can turn on auto-tuning with Oracle
3858+ 12.1 using an
3859+ [*oraaccess.xml*](https://github.com/oracle/node-oracledb/blob/master/doc/api.md#oraaccess) file.
3860+
3861+ For more information, see the [Statement Caching](https://github.com/oracle/node-oracledb/blob/master/doc/api.md#stmtcache) documentation.
3862+
3863+ - Use bind variables otherwise each variant of the statement will have
3864+ its own statement cache entry and cursor. With appropriate binding
3865+ only one entry and cursor will be needed.
3866+
3867+ - Set the database's
3868+ [*open_cursors*](http://docs.oracle.com/database/122/REFRN/OPEN_CURSORS.htm#REFRN10137) parameter
3869+ appropriately. This parameter specifies the maximum number of
3870+ cursors that each "session" (i.e each node-oracle connection) can
3871+ use. When a connection exceeds the value, the *ORA-1000* error is
3872+ thrown.
3873+
3874+ Along with a cursor per entry in the connection's statement cache,
3875+ any new statements that a connection is currently executing, or
3876+ ResultSets that haven't been released (in neither situation are
3877+ these yet cached), will also consume a cursor. Make sure that
3878+ *open_cursors* is large enough to accommodate the maximum open
3879+ cursors any connection may have. The upper bound required is
3880+ *stmtCacheSize* + the maximum number of executing statements in a
3881+ connection.
3882+
3883+ Remember this is all per connection. Also cache management happens
3884+ when statements are internally released. The majority of your
3885+ connections may use less than *open_cursors* cursors, but if one
3886+ connection is at the limit and it then tries to execute a new
3887+ statement, that connection will get *ORA-1000: maximum open cursors
3888+ exceeded*.
3889+
38133890## <a name="plsqlexecution"></a> 10. PL/SQL Execution
38143891
38153892PL/SQL stored procedures, functions and anonymous blocks can be called
0 commit comments