Chapter 4 Using a Cursor to Manipulate Data
This chapter describes how to use a cursor to manipulate data.
This chapter contains the following sections:
4.1 Cursor Overview
4.2 Declaring a Cursor
4.3 Opening and Closing a Cursor
4.4 Positioning a Cursor and Fetching Data
4.5 Updating Data Using a Cursor
4.6 Deleting Data Using a Cursor
4.1 Cursor Overview
A cursor is a virtual tool used to specify one row in a table. A cursor can be used in fetching, updating, or deleting data
in a row. Using a cursor to specify a row is called positioning the cursor.
A cursor is either in an open or closed state. If a cursor has never been opened, it is in a state equivalent to a closed
state. If a cursor can be used to manipulate data, it is in an open state.
When a cursor is in an open state, it may or may not be positioned on a specific row in a table. Understanding that a
cursor may be considered to be in the following four positions helps provide an understanding of the cursor:
· Immediately before the first row
· On a row
· Between two rows
· Immediately after the last row
Figure: Cursor overview provides a simple overview of the cursor using an abbreviated the STOCK table. Column
names have not been included in Figure: Cursor overview. The SQL statements used for various data manipulations
are explained later in this manual.
39