OPEN Statement [ESQL] [SP]

Opens a previously declared cursor to access information from the database.

Quick Links:

Go to Parameters

Go to Examples

Go to Usage

Go to Standards

Go to Permissions

Syntax

OPEN cursor-name
   ... [ USINGDESCRIPTORsqlda-name | host-variable [, …] } ] ]
   ... [ WITH HOLD ]

Parameters

(back to top)

Examples

(back to top)

Usage

(back to top)

By default, all cursors are automatically closed at the end of the current transaction (COMMIT or ROLLBACK).

The cursor is positioned before the first row.

A cursor declared using the FOR READ ONLY clause sees the version of table(s) on which the cursor is declared when the cursor is opened, not the version of table(s) at the time of the first FETCH statement.

The USING DESCRIPTOR sqlda-name, host-variable, and BLOCK n clauses are for Embedded SQL only.

After successful execution of the OPEN statement, the sqlerrd[3] field of the SQLCA (SQLIOESTIMATE) is filled in with an estimate of the number of input/output operations required to fetch all rows of the query. Also, the sqlerrd[2] field of the SQLCA (SQLCOUNT) is filled in with either the actual number of rows in the cursor (a value greater than or equal to 0), or an estimate thereof (a negative number whose absolute value is the estimate). The sqlerrd[2] field is the actual number of rows, if the database server can compute this value without counting the rows.

Standards

(back to top)

  • SQL—ISO/ANSI SQL compliant.
  • SAP Sybase Database product—The simple OPEN cursor-name syntax is supported by Adaptive Server. None of the other clauses are supported in Adaptive Server stored procedures. Open Client/Open Server supports the USING descriptor or host name variable syntax.

Permissions

(back to top)

  • Must have SELECT permission on all tables in a SELECT statement or EXECUTE permission on the procedure in a CALL statement.
  • When the cursor is on a CALL statement, OPEN causes the procedure to execute until the first result set (SELECT statement with no INTO clause) is encountered. If the procedure completes and no result set is found, the SQLSTATE_PROCEDURE_COMPLETE warning is set.
Related reference
CLOSE Statement [ESQL] [SP]
DECLARE CURSOR Statement [ESQL] [SP]
FETCH Statement [ESQL] [SP]
PREPARE Statement [ESQL]
RESUME Statement