Name
FETCH
Synopsis
FETCHcursor
INTOvariable
[, ...]
A cursor is similar to a table or a view: it represents,
within a procedure, a results set that is retrieved one row at a time
using this statement. You first establish a cursor with the DECLARE statement. Then you use the OPEN statement to initialize the cursor. The FETCH statement retrieves the next row of the cursor
and places the data retrieved into one or more variables. There should
be the same number of variables as there are columns in the underlying
SELECT
statement of the cursor. Variables are given
in a comma-separated list. Each execution of FETCH advances the pointer for the cursor by one
row. Once all rows have been fetched, an SQLSTATE of
02000
is returned. You can tie a condition to this
state through a DECLARE statement and end
fetches based on the condition. Use the CLOSE
statement to close a cursor.
Get MySQL in a Nutshell, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.