Progress
SQL-92
Guide and Reference


DECLARE CURSOR Statement

Associates a cursor with a static query or a prepared dynamic query statement. The query or the prepared statement can have references to host variables.

SYNTAX

DECLARE cursor_name CURSOR FOR 
  { query_expression [ ORDER BY clause ] [ FOR UPDATE clause ] 
     | prepared_statement_name 
  } ; 

cursor_name

A name you assign to the cursor. The name must meet the requirements for an identifier.

query_expression [ ORDER BY clause ] [FOR UPDATE clause ]

A complete query expression.

prepared_statement_name

The name assigned to a prepared SQL-92 statement in an earlier PREPARE statement.

EXAMPLES

This example illustrates static processing of a SELECT statement. This is a code fragment from the StatSel function in sample program 2StatSel.pc. The complete source for this sample program is in Appendix A of the Progress Embedded SQL-92 Guide and Reference .

EXEC SQL WHENEVER SQLERROR GOTO selerr ; 
EXEC SQL DECLARE stcur CURSOR FOR   
     SELECT InvTransNum, Qty, OrderNum FROM PUB.InventoryTrans ; 
EXEC SQL OPEN stcur ;       
EXEC SQL WHENEVER NOT FOUND GOTO seldone ; 

This example is a code fragment from the DynSel function in sample program 4DynSel.pc, which illustrates dynamic processing of a SELECT statement. The complete source for this sample program is in Appendix A of the Progress Embedded SQL-92 Guide and Reference .

EXEC SQL WHENEVER SQLERROR GOTO selerr ; 
EXEC SQL PREPARE stmtid from :sel_stmt_v ; 
EXEC SQL DECLARE dyncur CURSOR FOR stmtid ; 
EXEC SQL OPEN dyncur ;             
EXEC SQL WHENEVER NOT FOUND GOTO seldone ; 

NOTES

AUTHORIZATION

None (See AUTHORIZATION for the OPEN Statement)

SQL COMPLIANCE

SQL-92. Progress Extension: prepared_statement_name

ENVIRONMENT

Embedded SQL-92 only

RELATED STATEMENTS

PREPARE Statement, OPEN Statement, FETCH Statement, CLOSE Statement, SELECT Statement, "Query Expressions" in "SQL-92 Language Elements"


Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095