Documentation Home
MySQL 9.4 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 41.2Mb
PDF (A4) - 41.3Mb
Man Pages (TGZ) - 262.8Kb
Man Pages (Zip) - 368.8Kb
Info (Gzip) - 4.1Mb
Info (Zip) - 4.1Mb


MySQL 9.4 Reference Manual  / ...  / SQL Statements  / Compound Statement Syntax  / Cursors  /  Cursor FETCH Statement

15.6.6.3 Cursor FETCH Statement

FETCH [[NEXT] FROM]cursor_name INTOvar_name [,var_name] ...

This statement fetches the next row for theSELECT statement associated with the specified cursor (which must be open), and advances the cursor pointer. If a row exists, the fetched columns are stored in the named variables. The number of columns retrieved by theSELECT statement must match the number of output variables specified in theFETCH statement.

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 aNOT FOUND condition). For an example, seeSection 15.6.6, “Cursors”.

Be aware that another operation, such as aSELECT or anotherFETCH, may also cause the handler to execute by raising the same condition. If it is necessary to distinguish which operation raised the condition, place the operation within its ownBEGIN ... END block so that it can be associated with its own handler.