> For the complete documentation index, see [llms.txt](https://mariadb.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mariadb.com/docs/server/reference/sql-statements/programmatic-compound-statements/programmatic-compound-statements-cursors.md).

# Cursors

{% columns %}
{% column %}
{% content-ref url="/pages/KCZW4Ax8kEZhzyobR4KO" %}
[Cursor Overview](/docs/server/reference/sql-statements/programmatic-compound-statements/programmatic-compound-statements-cursors/cursor-overview.md)
{% endcontent-ref %}
{% endcolumn %}

{% column %}
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.
{% endcolumn %}
{% endcolumns %}

{% columns %}
{% column %}
{% content-ref url="/pages/RcwiziJSSwrj68zEWtVU" %}
[CLOSE](/docs/server/reference/sql-statements/programmatic-compound-statements/programmatic-compound-statements-cursors/close.md)
{% endcontent-ref %}
{% endcolumn %}

{% column %}
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.
{% endcolumn %}
{% endcolumns %}

{% columns %}
{% column %}
{% content-ref url="/pages/cZaOrftTHHATw01bJq1z" %}
[DECLARE CURSOR](/docs/server/reference/sql-statements/programmatic-compound-statements/programmatic-compound-statements-cursors/declare-cursor.md)
{% endcontent-ref %}
{% endcolumn %}

{% column %}
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.
{% endcolumn %}
{% endcolumns %}

{% columns %}
{% column %}
{% content-ref url="/pages/JmVwHUDLAk6iIOUFeNkq" %}
[FETCH](/docs/server/reference/sql-statements/programmatic-compound-statements/programmatic-compound-statements-cursors/fetch.md)
{% endcontent-ref %}
{% endcolumn %}

{% column %}
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.
{% endcolumn %}
{% endcolumns %}

{% columns %}
{% column %}
{% content-ref url="/pages/CpFSyda03eO8JgEr3dhb" %}
[OPEN](/docs/server/reference/sql-statements/programmatic-compound-statements/programmatic-compound-statements-cursors/open.md)
{% endcontent-ref %}
{% endcolumn %}

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