BEGIN
DECLARE userid varchar(64); -- id
-- 遍历数据结束标志
DECLARE done INT DEFAULT FALSE;
-- 游标
DECLARE cur_account CURSOR FOR select id from s_user where 1=1;
-- 将结束标志绑定到游标
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
-- 打开游标
OPEN cur_account;
-- 遍历
read_loop: LOOP
-- 取值 取多个字段
FETCH NEXT from cur_account INTO userid;
IF done THEN
LEAVE read_loop;
END IF;
-- 你自己想做的操作
insert into s_user_role(uid,rid) value(userid,7);
insert into s_user_role(uid,rid) value(userid,19);
END LOOP;
CLOSE cur_account;
END