7.5.22 OPEN

Table of Contents Previous Next



7.5.22 OPEN
Use the OPEN statement to open a cursor. The syntax is:
EXEC SQL [FOR array_size] OPEN cursor [USING parameters];
Where parameters is one of the following:
DESCRIPTOR SQLDA_descriptor
or
host_variable [ [ INDICATOR ] indicator_variable, … ]
array_size is an integer value or a host variable that contains an integer value specifying the number of rows to fetch. If you omit the FOR clause, the statement is executed once for each member of the array.
cursor is the name of the cursor being opened.
parameters is either DESCRIPTOR SQLDA_descriptor or a comma-separated list of host variables (and optional indicator variables) that initialize the cursor. If specifying an SQLDA_descriptor, the descriptor must be initialized with a DESCRIBE statement.
The OPEN statement initializes a cursor using the values provided in parameters. Once initialized, the cursor result set will remain unchanged unless the cursor is closed and re-opened. A cursor is automatically closed when an application terminates.
The following example declares a cursor named employees, that queries the emp table, returning the employee number, name, salary and commission of an employee whose name matches a user-supplied value (stored in the host variable, :emp_name).
After declaring the cursor, the example uses an OPEN statement to make the contents of the cursor available to a client application.


Table of Contents Previous Next