A cursor is a symbolic name that an application attaches to a select statement. The statement can be executed and its result set manipulated by performing operations on the cursor.
Cursors support the following operations:
Declare – create a new cursor by giving it a name and defining its query.
Set cursor rows – specify the number of rows from the result table to be returned with each fetch operation.
Open – execute the cursor’s query and prepare it for fetch operations.
Fetch – retrieve rows from the cursor, which must be open. Each fetch operation retrieves a single row from the query’s result table. This applies to both scrollable and non-scrollable cursors. Under certain conditions (as defined by the “set cursor rows” operation), more rows can be returned per fetch call.
Update – modify the values in a fetched row. The update affects the tables from which the row was selected.
Delete – remove a fetched row from an underlying table.
Close – ready the cursor to be either reopened or deallocated.
Deallocate – free the cursor’s resources.
In an Adaptive Server Enterprise client application, cursors can either be created and manipulated with language commands or with ct_cursor commands. Cursors created using Transact-SQL language commands are called language cursors. Cursors created with ct_cursor commands are called Client-Library cursors. Table 7-1 compares the two types of cursors.