mysql 游标使用范例!!
2010-08-27 12:00
525 查看
DELIMITER $$
DROP PROCEDURE IF EXISTS `ucenter`.`tttt`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `tttt`()
BEGIN
-- 定义本地变量
DECLARE o,z int;
declare no_more_departments int;
-- 定义游标
DECLARE ordernumbers CURSOR
FOR
select ids from t ;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET no_more_departments=1;
SET no_more_departments=0;
-- 打开游标
OPEN ordernumbers;
set z=0;
FETCH ordernumbers INTO o; -- 取一行到 o
WHILE no_more_departments!=1 DO
-- 开始处理一行
-- select o;
set z=z+1;
insert into uc_ego_members_vip (id,`user`, addpoint,addtime) select id,`user`,'5000' addpoint ,now() from uc_ego_members where id =o;
insert into uc_ego_point (`user`, buy, point, `time`,`type`,bigClassId,bigClassName,smallClassId,smallClassName,brandId,brandName,price,productId,productModel,productName) select `user`,'VIP升级加分','5000' addpoint ,now() `time`,1 `type`,0,'',0,'',0,'',0,0,'','' from uc_ego_members where id =o;
UPDATE uc_ego_members set EgoPoint=(EgoPoint+5000) where id =o;
FETCH ordernumbers INTO o; -- 取一行到 o
END WHILE;
select concat('共处理:',z,'行');-- 记数器
select no_more_departments;-- 条件值
-- 关闭游标
CLOSE ordernumbers;
END$$
DELIMITER ;
DROP PROCEDURE IF EXISTS `ucenter`.`tttt`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `tttt`()
BEGIN
-- 定义本地变量
DECLARE o,z int;
declare no_more_departments int;
-- 定义游标
DECLARE ordernumbers CURSOR
FOR
select ids from t ;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET no_more_departments=1;
SET no_more_departments=0;
-- 打开游标
OPEN ordernumbers;
set z=0;
FETCH ordernumbers INTO o; -- 取一行到 o
WHILE no_more_departments!=1 DO
-- 开始处理一行
-- select o;
set z=z+1;
insert into uc_ego_members_vip (id,`user`, addpoint,addtime) select id,`user`,'5000' addpoint ,now() from uc_ego_members where id =o;
insert into uc_ego_point (`user`, buy, point, `time`,`type`,bigClassId,bigClassName,smallClassId,smallClassName,brandId,brandName,price,productId,productModel,productName) select `user`,'VIP升级加分','5000' addpoint ,now() `time`,1 `type`,0,'',0,'',0,'',0,0,'','' from uc_ego_members where id =o;
UPDATE uc_ego_members set EgoPoint=(EgoPoint+5000) where id =o;
FETCH ordernumbers INTO o; -- 取一行到 o
END WHILE;
select concat('共处理:',z,'行');-- 记数器
select no_more_departments;-- 条件值
-- 关闭游标
CLOSE ordernumbers;
END$$
DELIMITER ;
相关文章推荐
- MySql游标的使用
- 关于MySQL游标的嵌套使用
- mysql 存储过程中使用游标中使用临时表可以替代数组效果
- mysql的cursor使用(游标)脚本创建
- MYSQL游标的使用
- mysql游标的使用
- mysql 游标使用
- Mysql游标使用
- 记录mysql 游标使用示例
- 数据库_MySQL 游标的使用和结果集的遍历
- mysql中游标的使用
- MySql中游标及存储过程的定义与使用方式
- Mysql的游标的定义使用及关闭深入分析
- mysql中使用存储过程,游标,定时任务
- MySql游标的使用
- 游标使用经典范例
- mysql存储过程 游标使用
- MYSQL存储过程中使用游标的实例
- mysql游标的使用 No data - zero rows fetched, selected
- mysql游标中使用临时表