sql游标循环实例_mysql循环遍历结果集

sql游标循环实例_mysql循环遍历结果集mysql for循环遍历 游标用处DROP PROCEDURE IF EXISTS testEndHandle;delimiter $$CREATE PROCEDURE testEndHandle()BEGIN DECLARE done BOOLEAN DEFAULT 0; D

mysql for循环遍历 游标用处   DROP PROCEDURE IF EXISTS testEndHandle; delimiter $$ CREATE PROCEDURE testEndHandle() BEGIN DECLARE done BOOLEAN DEFAULT 0; DECLARE tmp_uid INT DEFAULT 0; DECLARE tmp_uage INT DEFAULT 0; DECLARE tmp_region VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; DECLARE t_index CURSOR FOR SELECT region from comsumer10 where country=’中国’ GROUP BY region; — 写法一:DECLARE CONTINUE HANDLER FOR NOT FOUND SET done=1; — DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; — 写法二:DECLARE CONTINUE HANDLER FOR SQLSTATE ‘02000’ SET done = 1; DECLARE CONTINUE HANDLER FOR SQLSTATE ‘02000’ SET done = 1; OPEN t_index; REPEAT FETCH t_index INTO tmp_region; IF done!=1 THEN #create table results as SELECT country,region,city,count(*),sum(coin) from comsumer10 where region=tmp_region GROUP BY city ORDER BY sum(coin) desc; #insert into results SELECT country,region,city,count(*),sum(coin) from comsumer10 where region=tmp_region GROUP BY city ORDER BY sum(coin) desc; SELECT country,region,city,count(*),sum(coin) from comsumer10 where region=tmp_region GROUP BY city ORDER BY sum(coin) desc; END IF; UNTIL DONE END REPEAT; CLOSE t_index; END; $$ call testEndHandle(); #SELECT region from comsumer10 where country=’中国’ GROUP BY region;

2024最新激活全家桶教程,稳定运行到2099年,请移步至置顶文章:https://sigusoft.com/99576.html

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。 文章由激活谷谷主-小谷整理,转载请注明出处:https://sigusoft.com/65270.html

(0)
上一篇 2024年 8月 27日
下一篇 2024年 8月 27日

相关推荐

关注微信