时间:2021-07-01 10:21:17 帮助过:24人阅读
BEGIN /** * * 游标模版 * @author xuyw * @email xyw10000@163.com * @date 2014-05-19 */ /*游标数据变量 uid*/ DECLARE uid VARCHAR(128); DECLARE done INT DEFAULT 0; /*查询所有用户*/ DECLARE cur CURSOR FOR SELECT xxx FROM xx; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; OPEN cur; /* 开始循环*/ REPEAT /* 提取游标里的数据*/ FETCH cur INTO uid; IF done =0 THEN 执行你的业务 END IF; UNTIL done=1 END REPEAT; /*关闭游标*/ CLOSE cur; END;