关于Mysql使用存储过程,并且使用游标的Demo
2015-05-20 00:00
417 查看
DELIMITER $$ /* Mysql 创建存储过程 名为:new_pro */ CREATE DEFINER=`root`@`localhost` PROCEDURE `new_pro`() BEGIN /* 声明变量 并设定默认值 */ Declare not_found int default 0; Declare collectionId bigint; Declare children_collectionId bigint; /* 创建游标 通过查询表 channelcollection创建出游标 */ Declare idCursor cursor for select id from channelcollection where name='a' or name='c'; /* 异常处理,当发生异常的时候设定 not_found的值为1 */ Declare continue handler for not found set not_found=1; /* 设定collectionId的值为 查询出的ID */ set collectionId = (SELECT id FROM channelcollection where name='b' limit 1); /* 使用游标之前先打开游标 */ open idCursor; /* 循环游标并且把循环出来的游标赋值给 children_collectionId */ idCursor_loop: LOOP fetch idCursor into children_collectionId; if not_found=1 then leave idCursor_loop; else /* 将数据循环插入另外一个表 */ insert into channelcollectionfamily values (collectionId,children_collectionId); end if; end LOOP idCursor_loop; /* 使用完之后关闭游标 */ close idCursor; END
相关文章推荐
- MySQL 5.0 存储过程例子(使用了游标)
- 关于MySQL游标的嵌套使用
- MySQL中关于行转列的存储过程的写法(使用游标)
- MySQL中关于行转列的存储过程的写法(使用游标)
- MySql 使用存储过程和游标读取并更新数据
- mysql 存储过程 游标的使用 与定义
- mysql存储过程 游标 循环使用介绍
- Mysql创建存储过程,使用游标Cursor循环更新
- Mysql创建存储过程,使用游标Cursor循环更新
- mysql存储过程 游标 循环使用 含SQLSTATE mysql异常代码汇总大全
- mysql 使用游标进行删除操作的存储过程
- mysql 使用游标进行删除操作的存储过程
- 关于如何使用Navicat(11.1.13) for MySQL如何创建存储过程
- mysql 存储过程 -- 游标的使用(备忘)
- mysql存储过程 --游标的使用 取每行记录 (多字段)
- mysql中使用存储过程,游标,定时任务
- mysql中使用存储过程,游标,定时任务
- mysql 记录一次实际业务中使用到存储过程、游标
- mysql存储过程 游标使用
- MySQL存储过程学习整理,游标使用,参数输入输出