标签:mysql 循环
while 例如
DROP PROCEDURE IF EXISTS zy.test_pro;
DELIMITER $$
CREATE PROCEDURE zy.test_pro(IN id INT)
BEGIN
DECLARE num INT ;
SET num=1;
WHILE num <=id DO
INSERT INTO zy.test VALUES (num,CONCAT(‘test‘,num));
SET num = num +1;
END WHILE;
END;
repate
delimiter // drop procedure if exists looppc; create procedure looppc() begin declare i int; set i = 1; repeat insert into user_profile_company (uid) values (i+1); set i = i + 1; until i >= 20 end repeat; end // ---- 调用 call looppc()
loop
delimiter $$ drop procedure if exists lopp; create procedure lopp() begin declare i int ; set i = 1; lp1 : LOOP // lp1 为循环体名称 LOOP 为关键字 insert into user_profile (uid) values (i); set i = i+1; if i > 30 then leave lp1; // 离开循环体 end if; end LOOP; // 结束循环end $$
标签:mysql 循环
原文地址:http://12182612.blog.51cto.com/12172612/1982456