For the complete documentation index, see llms.txt. This page is also available as Markdown.

OPEN

Syntax

OPEN cursor_name [[USING variable[,...]] | [expression[,...]]];
-- From MariaDB 12.3
OPEN cursor_variable FOR dynamic_sql_string;
-- From MariaDB 13.1.1
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

OPEN ... FOR PREPARE and OPEN ... FOR LOCAL are available from MariaDB 13.1.1.

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 named stmt_name.

  • OPEN cursor_variable FOR LOCAL spvar; opens the cursor over the prepared statement whose name is the value of the stored-procedure variable spvar.

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

spinner

Last updated

Was this helpful?