<= MariaDB 10.2
DECLARE cursor_name CURSOR FOR select_statement
From MariaDB 10.3
DECLARE cursor_name CURSOR [(cursor_formal_parameter[,...])] FOR select_statement cursor_formal_parameter: name type [collate clause]
select_statement is not executed until the OPEN statement is executed. It is important to remember this if the query produces an error, or calls functions which have side effects.
SELECT associated to a cursor can use variables, but the query itself cannot be a variable, and cannot be dynamically composed. The
SELECT statement cannot have an
Cursors must be declared before
HANDLERs, but after local variables and
See Cursor Overview for an example.