BEGIN
DECLARE iEmail varchar(50);#参数iEmail的类型一定要和存入里面的数据类型一致
DECLARE iUserId int;
DECLARE NOTFOUND int DEFAULT 0;
DECLARE mycursor CURSOR FOR SELECT email FROM table;
DECLARE mycursor1 CURSOR FOR SELECT userId FROM table1 WHERE email=iEmail;#iEmail是从第一个游标获得的数据
DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' set NOTFOUND=1;
OPEN mycursor;
FETCH mycursor INTO iEmail;
WHILE (NOTFOUND = 0 AND iEmail IS NOT NULL) DO
OPEN mycursor1;
FETCH mycursor1 INTO iUserId;
WHILE(NOTFOUND=0 AND iUserId IS NOT NULL) DO
#在这里写处理的代码
FETCH mycursor1 INTO iUserId;
END WHILE;
CLOSE mycursor1;
SET NOTFOUND=0;
FETCH mycursor INTO iEmail;
END WHILE;
CLOSE mycursor;
END
mysql 嵌套游标的使用
最新推荐文章于 2023-07-18 23:41:36 发布