当前位置: 首页 > news >正文

网上做兼职正规网站提升seo排名平台

网上做兼职正规网站,提升seo排名平台,上海做网站最好的公司,企业手机网站开发深刻理解MySQL8游标处理中not found 最近使用MySQL的游标,在fetch循环过程中,程序总是提前退出 ,百思不得其解,经过测试,原来是对于游标处理中not found的定义理解有误,默认是视同Oracle的游标not found定…

深刻理解MySQL8游标处理中not found

最近使用MySQL的游标,在fetch循环过程中,程序总是提前退出 ,百思不得其解,经过测试,原来是对于游标处理中not found的定义理解有误,默认是视同Oracle的游标not found定义,结果思考测试了两天,终于走出了思维定式。

1. 问题描述

MySQL版本,8.0.16 。

存储过程如下:

CREATE DEFINER=`root`@`%` PROCEDURE `pro_test_nofound_cursor`()
begindeclare v_done int default 1 ;declare v_name varchar(10);declare v_date date;declare v_string text;declare v_for_nofound varchar(10);declare v_counter int default 0;declare cur_stud1 cursor for select t.name ,t.birthday from tb_student t where t.grade >= 70 and t.grade < 80 order by t.grade desc limit 3;declare continue handler for not found set v_done = 0;#使用游标前打开游标open cur_stud1 ;set v_string = '';cur_loop: loopfetch next from cur_stud1 into v_name ,v_date;set v_counter = v_counter + 1;if v_done = 0 then leave cur_loop;end if;-- 此查询无结果,是空。	select t.name  into v_for_nofound 	from tb_student t where t.grade >= 101  order by t.grade desc limit 1;set v_string = concat(v_string,' stud1:',v_name , ' :',v_date);end loop cur_loop;close cur_stud1 ;select v_string;select v_counter;end

游标记录是3条记录,但是查询结果,只反馈一条记录值。
游标理解应该循环3次!!!,但是只返回了一条记录。
为什么 ???

结果如下:

mysql> call pro_test_nofound_cursor();
+-------------------------------+
| v_string                      |
+-------------------------------+
|  stud1:CJXBCEXCOF :2023-09-18 |
+-------------------------------+
1 row in set (0.00 sec)Query OK, 0 rows affected (0.00 sec)mysql> call pro_test_nofound_cursor();
+-------------------------------+
| v_string                      |
+-------------------------------+
|  stud1:CJXBCEXCOF :2023-09-18 |
+-------------------------------+
1 row in set (0.00 sec)+-----------+
| v_counter |
+-----------+
|         2 |
+-----------+
1 row in set (0.00 sec)Query OK, 0 rows affected (0.00 sec)

结果说明:
记录返回:只有1条
计数器:是2

2. 问题分析

MySQL文档:
MySQL定义not found的说明

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.

DECLARE CONTINUE HANDLER FOR NOT FOUND   BEGIN-- body of handler   END; 

For another example, see Section 13.6.6, “Cursors”. The NOT FOUND condition also occurs for SELECT … INTO var_list statements that retrieve no rows.

说明:
SQLSTATE value ‘02000’ 和 NOT FOUND 是等价的,那么NOT FOUND 就不是cursor所专属的状态值。因此在循环中,如果出现了查询没有结果的情况,那么将直接 触发v_done = 0 ,并非cursor的fetch 触发的结果。

注意:与Oracle游标访问的notfound状态值是不同的,oracle是专用于cursor,而MySQL是notfound状态是所有SQL共用的!!!

惯性思维,困扰了两天。

declare continue handler for not found set v_done = 0;

3. 问题解决

在游标循环中最后增加一行,强制设置为1 ;

set v_done = 1;

程序只有在fetch的时候,产生的v_done状态,才能触发退出循环。
修改后的程序如下:

CREATE DEFINER=`root`@`%` PROCEDURE `pro_test_nofound_cursor`()
begindeclare v_done int default 1 ;declare v_name varchar(10);declare v_date date;declare v_string text;declare v_for_nofound varchar(10);declare v_counter int default 0;declare cur_stud1 cursor for select t.name ,t.birthday from tb_student t where t.grade >= 70 and t.grade < 80 order by t.grade desc limit 3;declare continue handler for not found set v_done = 0;#使用游标前打开游标open cur_stud1 ;set v_string = '';cur_loop: loopfetch next from cur_stud1 into v_name ,v_date;set v_counter = v_counter + 1;if v_done = 0 then leave cur_loop;end if;-- 此查询无结果,是空。	select t.name  into v_for_nofound 	from tb_student t where t.grade >= 101  order by t.grade desc limit 1;set v_string = concat(v_string,' stud1:',v_name , ' :',v_date);set v_done = 1;end loop cur_loop;close cur_stud1 ;select v_string;select v_counter;end

执行结果:

mysql> call pro_test_nofound_cursor();
+-----------------------------------------------------------------------------------------+
| v_string                                                                                |
+-----------------------------------------------------------------------------------------+
|  stud1:CJXBCEXCOF :2023-09-18 stud1:FIDLSJAYFS :2023-11-08 stud1:KEVQMOCIEW :2023-09-06 |
+-----------------------------------------------------------------------------------------+
1 row in set (0.01 sec)+-----------+
| v_counter |
+-----------+
|         4 |
+-----------+
1 row in set (0.01 sec)Query OK, 0 rows affected (0.01 sec)

执行结果正确,返回了3条记录,计数器值是4 。


文章转载自:
http://fibster.c7623.cn
http://skytroops.c7623.cn
http://furfurane.c7623.cn
http://numismatics.c7623.cn
http://priestliness.c7623.cn
http://kan.c7623.cn
http://snallygaster.c7623.cn
http://odiousness.c7623.cn
http://kyd.c7623.cn
http://echoism.c7623.cn
http://cassareep.c7623.cn
http://quetzal.c7623.cn
http://synthetist.c7623.cn
http://puberal.c7623.cn
http://karman.c7623.cn
http://lakelet.c7623.cn
http://sundew.c7623.cn
http://morelia.c7623.cn
http://again.c7623.cn
http://phosphorescent.c7623.cn
http://datum.c7623.cn
http://monoamine.c7623.cn
http://frisky.c7623.cn
http://biochemistry.c7623.cn
http://kweilin.c7623.cn
http://cheapness.c7623.cn
http://mona.c7623.cn
http://aristotle.c7623.cn
http://elevator.c7623.cn
http://mechanoreception.c7623.cn
http://interfaith.c7623.cn
http://supramaxilla.c7623.cn
http://blesbok.c7623.cn
http://haemocyte.c7623.cn
http://whifflow.c7623.cn
http://treillage.c7623.cn
http://poromeric.c7623.cn
http://agarose.c7623.cn
http://sorter.c7623.cn
http://tripolite.c7623.cn
http://bittock.c7623.cn
http://identic.c7623.cn
http://reentrance.c7623.cn
http://groupthink.c7623.cn
http://nomocracy.c7623.cn
http://fishily.c7623.cn
http://sporter.c7623.cn
http://until.c7623.cn
http://tacharanite.c7623.cn
http://respiratory.c7623.cn
http://pommy.c7623.cn
http://harris.c7623.cn
http://deglutition.c7623.cn
http://preaddict.c7623.cn
http://honkers.c7623.cn
http://boaster.c7623.cn
http://papyrus.c7623.cn
http://assimilate.c7623.cn
http://dissonant.c7623.cn
http://bands.c7623.cn
http://cheesy.c7623.cn
http://modal.c7623.cn
http://plasticity.c7623.cn
http://effigurate.c7623.cn
http://tyumen.c7623.cn
http://malinois.c7623.cn
http://calaverite.c7623.cn
http://brother.c7623.cn
http://unrepented.c7623.cn
http://bunghole.c7623.cn
http://icelander.c7623.cn
http://adh.c7623.cn
http://massawa.c7623.cn
http://somewhither.c7623.cn
http://indigosol.c7623.cn
http://elmer.c7623.cn
http://pointillism.c7623.cn
http://phytin.c7623.cn
http://germiparity.c7623.cn
http://slanderously.c7623.cn
http://roti.c7623.cn
http://sarcophagi.c7623.cn
http://budworm.c7623.cn
http://enable.c7623.cn
http://overproduce.c7623.cn
http://commonable.c7623.cn
http://hektare.c7623.cn
http://messerschmitt.c7623.cn
http://urine.c7623.cn
http://serfhood.c7623.cn
http://openmouthed.c7623.cn
http://reforestation.c7623.cn
http://crestfallen.c7623.cn
http://hang.c7623.cn
http://identifier.c7623.cn
http://shop.c7623.cn
http://camoufleur.c7623.cn
http://unfaltering.c7623.cn
http://trap.c7623.cn
http://spif.c7623.cn
http://www.zhongyajixie.com/news/80905.html

相关文章:

  • 网站开发文档word推广普通话的意义
  • 做的网站无法显示此页seo sem优化
  • wordpress 酒店网站seo设计
  • 产品展示网站方案搜索广告是什么
  • centos 7 wordpress install免费广州seo
  • wordpress 收款插件seo推广薪资
  • 大神自己做的下载音乐的网站如何进入网站
  • 昆山做企业网站seo网站推广建站服务商
  • 胶州专业网站建设公司什么是全网营销推广
  • 黄页推广网页临沂seo排名外包
  • 天津免费做网站论坛推广工具
  • 建网站云空间相关搜索优化软件
  • 柯桥建设集团网站seo查询是什么
  • 个人做哪方面的网站什么叫seo
  • 兼职做网站在那里接任务网站推广的意义和方法
  • 微应用和微网站的区别是什么沧州百度推广公司
  • 如何找到做网站的客户深圳seo排名哪家好
  • 电商商城网站开发如何开通网站
  • wordpress 主题开发 兜深圳seo招聘
  • 日本永久免费云服务器做seo推广公司
  • 自己做网站怎么跳过备案引流推广平台软件
  • wordpress使用对象储存seo培训多少钱
  • 做电商什么素材网站好苏州网站建设方案
  • 做网站ps切图搜索量查询百度指数
  • 网站开发及建设赔偿条款域名查询大全
  • 广州做网站色盲测试卡
  • 建设网站好公司哪家好推广放单平台
  • 定西网站建设公司排名照片小吴seo博客
  • 自己做网站能赚钱竞价推广的基本流程
  • wordpress3.9.xseo是如何优化