· 8 years ago · Jul 14, 2018, 01:04 PM
1DELIMITER $$
2CREATE PROCEDURE ABC()
3
4 BEGIN
5 DECLARE a INT Default 0 ;
6 simple_loop: LOOP
7 SET a=a+1;
8 select a;
9 IF a=5 THEN
10 LEAVE simple_loop;
11 END IF;
12 END LOOP simple_loop;
13END $$
14
15drop table if exists foo;
16create table foo
17(
18id int unsigned not null auto_increment primary key,
19val smallint unsigned not null default 0
20)
21engine=innodb;
22
23drop procedure if exists load_foo_test_data;
24
25delimiter #
26create procedure load_foo_test_data()
27begin
28
29declare v_max int unsigned default 1000;
30declare v_counter int unsigned default 0;
31
32 truncate table foo;
33 start transaction;
34 while v_counter < v_max do
35 insert into foo (val) values ( floor(0 + (rand() * 65535)) );
36 set v_counter=v_counter+1;
37 end while;
38 commit;
39end #
40
41delimiter ;
42
43call load_foo_test_data();
44
45select * from foo order by id;