Cursor (databases)
Encyclopedia : C : CU : CUR : Cursor (databases)
In database packages, the term cursor refers to a control structure for the successive (and potential processing) of records in a result set as returned by a query.
Cursors may be implemented on the client side or the server side of the database connection. A client-side cursor is necessary for processing individual rows returned from the database because many languages do not offer any other mechanism for manipulating individual rows in the result set. In this way, a cursor can be thought of as an iterator over the collection of rows in the result set.
Several database operations do not provide an opportunity for the use of cursors. The INSERT statement, for example, as well as most forms of the DELETE and UPDATE statements. Even a SELECT statement may not involve the use of a cursor if it returns no rows, or only one row.
On the server side, a cursor similarly allows an SQL statement's results to be used or examined one row at a time. Typically, server-side cursors are not necessary because most statements can be written using other SQL constructs that allow the database to carry out the intended operations more efficiently. They are rarely required.
Types of cursors: Static, Dynamic, Forward-only, Keyset-driven.
Disadvantages of cursors: Each time you fetch a row from the cursor, it results in a network round trip, where as a normal SELECT query makes only one round trip, however large the result set is. Cursors are also costly because they require more resources and temporary storage (results in more I/O operations). Further, there are restrictions on the SELECT statements that can be used with some types of cursors.
References
- Christopher J. Date: Database in Depth, O'Reilly & Associates, ISBN 0-596-10012-4
- Thomas M. Connolly, Carolyn E. Begg: Database Systems, Addison-Wesley, ISBN 0-321-21025-5
- Ramiz Elmasri, Shamkant B. Navathe: Fundamentals of Database Systems, Addison-Wesley, ISBN 0201542633
- Neil Matthew, Richard Stones: Beginning Databases with PostgreSQL: From Novice to Professional, Apress, ISBN 1590594789
- Thomas Kyte: Expert One-On-One: Oracle, Apress, ISBN 1-59059-525-4
See also
External links
- [Description from ODBC Programmer's Reference]
- [Descriptions from Portland Pattern Repository]
- [PostgreSQL Documentation]
- [Berkeley DB Reference Guide: Cursor operations]
- [Moving the Cursor in Scrollable Result Sets]
- [http://java.sun.com/j2se/1.5.0/docs/guide/jdbc/getstart/resultset.html ResultSet in JDBC]
- [Q3SqlCursor Class Reference]
- [OCI Scrollable Cursor]
- [function oci_new_cursor]
- [Citations by CiteSeer]
- [MySQL's Cursor Documentation]
- [Microsoft SQL Server Cursor Documentation]
From Wikipedia, the Free Encyclopedia. Original article here. Support Wikipedia by contributing or donating.
All text is available under the terms of the GNU Free Documentation License See Wikipedia Copyrights for details.
