没有,但有while,例子↓
declare i int// 变量声明set i = 1
while i < 11 do // 循环体
insert into user_profile (uid) values (i)
set i = i +1
end while
换个写法,mysql里面我也不知道如何用 for in loop来处理。例如:
CREATE PROCEDURE curdemo()
BEGIN
DECLARE done INT DEFAULT FALSE
DECLARE a CHAR(16)
DECLARE b, c INT
DECLARE cur1 CURSOR FOR SELECT id,data FROM test.t1
DECLARE cur2 CURSOR FOR SELECT i FROM test.t2
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE
OPEN cur1
OPEN cur2
read_loop: LOOP
FETCH cur1 INTO a, b
FETCH cur2 INTO c
IF done THEN
LEAVE read_loop
END IF
IF b <c THEN
INSERT INTO test.t3 VALUES (a,b)
ELSE
INSERT INTO test.t3 VALUES (a,c)
END IF
END LOOP
CLOSE cur1
CLOSE cur2
END
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)