mysql游标循环表与存储过程传参
发布日期:2021-06-29 11:46:47
浏览次数:3
分类:技术文章
本文共 1548 字,大约阅读时间需要 5 分钟。
drop procedure if exists proc_tmp;create procedure proc_tmp(in cnt int)BEGIN/*这种写法也可以:DECLARE done INT DEFAULT FALSE;*/declare done int default 0; /*用于判断是否结束循环*/declare zoneCode varchar(100); /*用于存储结果集S_S的记录(因为我这里S_S的记录只有一列且为bigint类型)*//*定义游标*/declare zoneCur cursor for select code from demo_zone where code!='Q07';/*定义 设置循环结束标识done值怎么改变 的逻辑*/declare continue handler for not FOUND set done = 1; /*done = true;亦可*/open zoneCur; /*打开游标*//* 循环开始 */REPEAT/* 如果要fetch多列应该这样写,fetch idCur into rowId, rowName 但是注意rowId和rowName要先declare,且declare cur时也要select两列,且这两列和rowId、rowName对应 */fetch zoneCur into zoneCode; /*这部分可以看看书,还可以fetch多列(假设结果集S_S的记录不是单列的话)*/if not done THEN /*数值为非0,MySQL认为是true*/INSERT INTO `hznet_demo`.`sys_station`(`id`, `name`, `type`, `stationid`, `remark`, `longitude`, `latitude`, `enable_control`, `stationsts`, `stationpic`, `code`, `svnaddress`) select 10000000+@rowNum:=@rowNum + 1, temp.`name`, temp.`type`, 10000000+@rowNum:=@rowNum, temp.`remark`, temp.`longitude`+0.1, temp.`latitude`+0.1, temp.`enable_control`, temp.`stationsts`, temp.`stationpic`, temp.`code`, temp.`svnaddress`from sys_station a,(SELECT @rowNum:=(select count(1) from sys_station)) b,(select `name`, `type`, `remark`, `longitude`, `latitude`, `enable_control`, `stationsts`, `stationpic`, `code`, `svnaddress`from sys_station a, demo_station_config cwhere a.stationid=c.stationid and a.stationid not in (0,1,2,3) and c.zone_code=zoneCode limit 1) temp limit cnt;end if;until done end repeat;close zoneCur; /*关闭游标*/END/* 循环结束 */-- call proc_tmp(40);
转载地址:https://blog.csdn.net/zzchances/article/details/103678814 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
第一次来,支持一个
[***.219.124.196]2024年04月24日 19时03分06秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
docker系列2: windows安装docker
2019-04-29
hbase数据转移: 导入导出
2019-04-29
docker系列7: docker搭建mysql
2019-04-29
windows server 2012设置远程连接断开后自动注销
2019-04-29
python基础:list,map,open()文件读写
2019-04-29
Go面向对象-接口
2019-04-29
Go-多路选择和超时控制
2019-04-29
Go-channel的关闭和广播
2019-04-29
Go-任务的取消
2019-04-29
AIX 作为Web Server 使用时,tcp相关的几个参数调整
2019-04-29
自我学习37:请描述一下网页从开始请求到最后展示的完整过程
2019-04-29
自我学习38:如何区分前后端BUG
2019-04-29
自我学习39:接口自动化测试用例&功能测试用例区别
2019-04-29
mirror去兔子补丁下载 附安装教程
2019-04-29
mirror去兔子补丁 v3.0附安装教程
2019-04-29
mirror去兔子补丁为什么还有兔子_mirror去兔子补丁使用教程
2019-04-29
3dmax2012安装教程
2019-04-29
OC渲染器(Octane Render)整合版安装包 附安装教程
2019-04-29
操作系统期末大题复习
2019-04-29
hive:分区表,hbase外表
2019-04-29