8. SQL Statements : DECLARE CURSOR : Description
 
Share this page                  
Description
DECLARE CURSOR is a compile-time statement and must appear before the first statement that references the cursor. Despite its declarative nature, a DECLARE CURSOR statement must not be located in a host language variable declaration section. A cursor cannot be declared for repeated select.
A typical cursor-based program performs the following steps:
1. Issue a DECLARE CURSOR statement to associate a cursor with a SELECT statement.
2. Open the cursor. When the cursor is opened, the DBMS Server executes the SELECT statement that was specified in the DECLARE CURSOR statement.
3. Process rows one at a time. The FETCH statement returns one row from the results of the SELECT statement that was executed when the cursor was opened. Rows can be retrieved in any sequence if a scrollable cursor is declared.
4. Close the cursor by issuing the CLOSE statement.
You can use SELECT * in a cursor SELECT statement.