> 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/fetch.md).

# FETCH

## Syntax

```bnf
FETCH cursor_name INTO var_name [, var_name] ...
```

## Description

This statement fetches the next row (if a row exists) using the specified [open](/docs/server/reference/sql-statements/programmatic-compound-statements/programmatic-compound-statements-cursors/open.md) [cursor](/docs/server/reference/sql-statements/programmatic-compound-statements/programmatic-compound-statements-cursors.md), and advances the cursor pointer.

`var_name` can be a [local variable](/docs/server/reference/sql-statements/programmatic-compound-statements/declare-variable.md), but *not* a [user-defined variable](/docs/server/reference/sql-structure/sql-language-structure/user-defined-variables.md).

If no more rows are available, a No Data condition occurs with`SQLSTATE` value `02000`. To detect this condition, you can set up a handler for it (or for a `NOT FOUND` condition).

See [Cursor Overview](/docs/server/reference/sql-statements/programmatic-compound-statements/programmatic-compound-statements-cursors/cursor-overview.md) for an example.

## See Also

* [Cursor Overview](/docs/server/reference/sql-statements/programmatic-compound-statements/programmatic-compound-statements-cursors/cursor-overview.md)
* [DECLARE CURSOR](/docs/server/reference/sql-statements/programmatic-compound-statements/programmatic-compound-statements-cursors/declare-cursor.md)
* [OPEN cursor\_name](/docs/server/reference/sql-statements/programmatic-compound-statements/programmatic-compound-statements-cursors/open.md)
* [CLOSE cursor\_name](/docs/server/reference/sql-statements/programmatic-compound-statements/programmatic-compound-statements-cursors/close.md)
* [Cursors in Oracle mode](/docs/release-notes/community-server/about/compatibility-and-differences/sql_modeoracle.md)

<sub>*This page is licensed: GPLv2, originally from*</sub> [<sub>*fill\_help\_tables.sql*</sub>](https://github.com/MariaDB/server/blob/main/scripts/fill_help_tables.sql)

{% @marketo/form formId="4316" %}
