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.
查看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.
相关文章推荐
- MySql中使用游标遍历记录并生成结果
- 不用游标 遍历记录的sql语句
- mysql 遍历游标 处理
- mysql存储过程简单实例 变量赋值 游标遍历
- mysql存储过程之游标遍历数据表
- linux环境下安装mysql的完整记录
- mysql遍历所有表,删除符合条件的记录的存储过程
- Mysql Binlog快速遍历搜索记录及binlog数据查看的方法
- 创建角色随机名字(mysql抽取随机记录)和mysql游标的使用
- 不用游标也能遍历记录的sql语句实例
- mysqlbinlog快速遍历搜索记录
- mysql存储过程之游标遍历数据表
- 游标与其它的遍历行记录方式
- Mysql之WHILE替代游标实现子母表三层遍历拷贝
- sql通过游标遍历某个数据库中所有的表,按某种需求筛选出对应的记录
- 游标遍历%rowtype中的记录
- Mysql之WHILE替代游标实现子母表三层遍历拷贝
- mysql存储过程之游标遍历数据表
- mysql 存储过程结合游标修改每一行记录的值