OPEN
Syntax
OPEN cursor_name [[USING variable[,...]] | [expression[,...]]];OPEN cursor_variable FOR dynamic_sql_string;OPEN cursor_variable FOR PREPARE stmt_name;
OPEN cursor_variable FOR LOCAL spvar;Description
This statement opens a cursor which was previously declared with DECLARE CURSOR.
The query associated to the DECLARE CURSOR is executed when OPEN is executed. It is important to remember this if the query produces an error, or calls functions which have side effects.
This is necessary in order to FETCH rows from a cursor.
See Cursor Overview for an example.
Opening a Cursor Over a Prepared Statement
In Oracle mode, a SYS_REFCURSOR can be opened over an already-prepared statement:
OPEN cursor_variable FOR PREPARE stmt_name;opens the cursor over the prepared statement namedstmt_name.OPEN cursor_variable FOR LOCAL spvar;opens the cursor over the prepared statement whose name is the value of the stored-procedure variablespvar.
OPEN ... FOR LOCAL is only valid inside a stored procedure, and like the other LOCAL forms is not permitted in stored functions or triggers.
OPEN ... FOR PREPARE counts as dynamic SQL, so inside a stored function it is subject to the same restriction as PREPARE and EXECUTE — see Dynamic SQL in Stored Functions.
Both forms require a weak cursor variable (SYS_REFCURSOR). Using them with a strongly-typed REF CURSOR (one declared with a RETURN clause) returns an error.
See Also
This page is licensed: GPLv2, originally from fill_help_tables.sql
Last updated
Was this helpful?

