在MySQL中,我有一个带有For循环的存储过程:DELIMITER $$ CREATE PROCEDURE ABC() BEGIN DECLARE a INT Default 0 ; simple_loop: LOOP SET a=a+1; select a; IF a=5 THEN LEAVE simple_loop; END IF; END LOOP simple_loop;END $$它总是打印1。MySQL for循环的正确语法是什么?
3 回答
小怪兽爱吃肉
TA贡献1852条经验 获得超1个赞
drop table if exists foo;
create table foo
(
id int unsigned not null auto_increment primary key,
val smallint unsigned not null default 0
)
engine=innodb;
drop procedure if exists load_foo_test_data;
delimiter #
create procedure load_foo_test_data()
begin
declare v_max int unsigned default 1000;
declare v_counter int unsigned default 0;
truncate table foo;
start transaction;
while v_counter < v_max do
insert into foo (val) values ( floor(0 + (rand() * 65535)) );
set v_counter=v_counter+1;
end while;
commit;
end #
delimiter ;
call load_foo_test_data();
select * from foo order by id;
添加回答
举报
0/150
提交
取消