13.6.6.2 Cursor DECLARE Statement语句

DECLARE cursor_name CURSOR FOR select_statement

This statement declares a cursor and associates it with a SELECT statement that retrieves the rows to be traversed by the cursor. 此语句声明一个指针并将其与一个SELECT语句相关联,SELECT语句检索指针要遍历的行。To fetch the rows later, use a FETCH statement. 要稍后提取行,请使用FETCH语句。The number of columns retrieved by the SELECT statement must match the number of output variables specified in the FETCH statement.SELECT语句检索到的列数必须与FETCH语句中指定的输出变量数匹配。

The SELECT statement cannot have an INTO clause.SELECT语句不能有INTO子句。

Cursor declarations must appear before handler declarations and after variable and condition declarations.指针声明必须出现在处理程序声明之前,变量和条件声明之后。

A stored program may contain multiple cursor declarations, but each cursor declared in a given block must have a unique name. 存储程序可以包含多个指针声明,但给定块中声明的每个指针必须具有唯一的名称。For an example, see Section 13.6.6, “Cursors”.有关示例,请参见第13.6.6节,“指针”

For information available through SHOW statements, it is possible in many cases to obtain equivalent information by using a cursor with an INFORMATION_SCHEMA table.对于通过SHOW语句获得的信息,在许多情况下,可以通过使用带有INFORMATION_SCHEMA表的指针来获得等效的信息。