OPEN
The OPEN statement is used in SQL Script to open a cursor. Two types of OPEN statements are available, one to open a static cursor and another to open a variable cursor. The OPEN statement for a variable cursor can specify whether it is for a query expression or a value expression. See Value Expressions.
Syntax (Open Static Cursor)
OPEN <cursor>
Syntax (Open Variable Cursor)
OPEN <cursorVariableName> FOR <queryExpression>
Remarks
| • | A cursor variable can be opened and initialized using a dynamic SQL statement as follows: |
OPEN <cursorVariableName> FOR <valueExpression>
| • | OPEN is similar to preparing a statement for execution. |
| • | Run-time errors, such as insufficient privileges, are not caught until a statement is executed. |
| • | The syntax for the open static cursor statement works on both static and variable cursors, although you get an error if you open an uninitialized cursor variable. |
| • | It is illegal to open a cursor that is already open. |
Errors
Standard parser and resolver errors can result from the SELECT statement in the FOR clause. The following table describes the errors that can occur when executing an OPEN statement.
|
Error Message |
Cause |
|
Cannot open a PIPE |
An attempt is made to open a PIPE variable. |
|
Uninitiallized cursor |
A cursor variable is used and is not initialized at the time it is opened. |
|
Cursor already open |
OPEN was invoked when the cursor was already open. |