13.6.6.3 Cursor FETCH Statement语句

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

This statement fetches the next row for the SELECT statement associated with the specified cursor (which must be open), and advances the cursor pointer. 此语句获取与指定指针(必须是打开的)关联的SELECT语句的下一行,并前进游标指针。If a row exists, the fetched columns are stored in the named variables. 如果存在行,则获取的列存储在命名变量中。The number of columns retrieved by the SELECT statement must match the number of output variables specified in the FETCH statement.SELECT语句检索到的列数必须与FETCH语句中指定的输出变量数匹配。

If no more rows are available, a No Data condition occurs with SQLSTATE value '02000'. 如果没有更多的行可用,则会出现无数据条件,SQLSTATE值为'02000'To detect this condition, you can set up a handler for it (or for a NOT FOUND condition). 要检测此条件,可以为其设置处理程序(或为NOT FOUND条件)。For an example, see Section 13.6.6, “Cursors”.有关示例,请参见第13.6.6节,“指针”

Be aware that another operation, such as a SELECT or another FETCH, may also cause the handler to execute by raising the same condition. 请注意,另一个操作(如SELECT或另一个FETCH)也可能通过引发相同的条件来导致处理程序执行。If it is necessary to distinguish which operation raised the condition, place the operation within its own BEGIN ... END block so that it can be associated with its own handler.如果有必要区分是哪个操作引起了这种情况,请将该操作置于其自身的BEGIN ... END块内,以便它可以与自己的处理程序相关联。