您的位置:首页 > 数据库 > MySQL

MySql游标遍历的记录数不完整

2016-12-07 13:56 447 查看
在项目中使用MySql存储过程中,使用游标遍历数据,发现定义游标的查询语句有8条记录,循环遍历的时候却只循环了一次;

查看MySql官方文档才发现,不仅到达游标结尾会有NOT FOUND condition发生,select … into …,没有查到数据,同样也会有NOT FOUND condition发生,因此在遍历游标循环里使用select … into … 以后,一定要把循环标志位置位;MySql官方文档说明如下:

NOT FOUND: Shorthand for the class of SQLSTATE values that begin with ‘02’. This is relevant within the context of cursors and is used to control what happens when a cursor reaches the end of a data set. 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 a NOT FOUND condition.

The NOT FOUND condition also occurs for SELECT … INTO var_list statements that retrieve no rows.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: