Opens a previously declared cursor to access information from the database.
OPEN cursor-name ... [ USING [ DESCRIPTOR { sqlda-name | host-variable [, ...] } ] ] ... [ WITH HOLD ]
identifier or host-variable
identifier
The following examples show the use of OPEN in Embedded SQL.
1. EXEC SQL OPEN employee_cursor; 2. EXEC SQL PREPARE emp_stat FROM 'SELECT empnum, empname FROM employee WHERE name like ?'; EXEC SQL DECLARE employee_cursor CURSOR FOR emp_stat; EXEC SQL OPEN employee_cursor USING :pattern;
The following example is from a procedure.
BEGIN DECLARE cur_employee CURSOR FOR SELECT emp_lname FROM employee ; DECLARE name CHAR(40) ; OPEN cur_employee; LOOP FETCH NEXT cur_employee into name ; ... END LOOP CLOSE cur_employee; END
The OPEN statement opens the named cursor. The cursor must be previously declared.
By default, all cursors are automatically closed at the end of the current transaction (COMMIT or ROLLBACK). The optional WITH HOLD clause keeps the cursor open for subsequent transactions. The cursor remains open until the end of the current connection or until an explicit CLOSE statement is executed. Cursors are automatically closed when a connection is terminated.
The cursor is positioned before the first row (see Chapter 8, “Using Procedures and Batches” of the Sybase IQ System Administration Guide).
The USING DESCRIPTOR sqlda-name, host-variable and BLOCK n formats are for Embedded SQL only.
If the cursor name is specified by an identifier or string, then the corresponding DECLARE CURSOR STATEMENT must appear prior to the OPEN in the C program; if the cursor name is specified by a host variable, then the DECLARE cursor statement must execute before the OPEN statement.
The optional USING clause specifies the host variables that will be bound to the place-holder bind variables in the SELECT statement for which the cursor has been declared.
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.
None.
SQL/92 Embedded SQL use is an entry-level feature. Procedures use is a Persistent Stored Modules feature.
Sybase The simple OPEN cursor-name syntax is supported by Adaptive Server Enterprise. None of the other clauses are supported in Adaptive Server Enterprise stored procedures. Open Client/Open Server supports the USING descriptor or host name variable syntax.
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.