mysql存储过程游标嵌套循环
自己写的一个mysql存储过程如下: BEGIN DECLARE _did bigint(20); DECLARE _count int; DECLARE s1 int; DECLARE cur_1 CURSOR FOR select id from info; /** 声明游标,并将查询结果存到游标中 **/ /** 获取查询数量 **/ SELECT count(id) into _count from info; SET s1=1; START TRANSACTION;#开启事务 open cur_1;#打开游标 while s1<_count+1 DO FETCH cur_1 INTO _did; -- 嵌套使用游标 BEGIN #声明变量 DECLARE token int DEFAULT 0; DECLARE _d int; DECLARE _t int; DECLARE _bdate datetime; #定义一个游标 DECLARE cur_2 CURSOR FOR select rr.da,rr.ts from rr left join info di on di.r_id = rr.id where di.id = _did; DECLARE CONTINUE HANDLER FOR NOT FOUND SET token=1; #开始循环游标 open cur