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

Cursors

Learn about cursors in MariaDB Server's programmatic compound statements. This section details how to iterate over result sets row-by-row within stored procedures and functions.

Introduces cursors in MariaDB stored programs, which are non-scrollable, read-only, and asensitive, and are declared, opened, fetched from, and closed to process result rows sequentially.

CLOSE closes a previously opened cursor, raising an error if it was not open; if not closed explicitly, a cursor closes at the end of its enclosing compound statement.

DECLARE CURSOR declares a named cursor for a SELECT or, from MariaDB 12.3, a prepared statement name, optionally with parameters, for use within a stored program.

FETCH retrieves the next row from an open cursor into local variables and advances the cursor, raising a No Data condition (SQLSTATE 02000) when no more rows remain.

OPEN opens a previously declared cursor and executes its associated query, optionally binding variables or expressions, so that rows can be fetched.

This page is licensed: CC BY-SA / Gnu FDL

Last updated

Was this helpful?