可以在客戶端裡面直接寫 比如用 navicat 就寫:
delimiter $$;
create procedure lucia_proc16(count int)
begin
DECLARE name_proc VARCHAR(20) CHARACTER SET utf8;
DECLARE sex_proc VARCHAR(4) CHARACTER SET utf8;
DECLARE age_proc INT(10);
DECLARE class_proc VARCHAR(20) CHARACTER SET utf8;
DECLARE Addr_proc VARCHAR(50) CHARACTER SET utf8;
DECLARE i INT;
set i = 1;
set sex_proc = "女";
set age_proc = 20;
set class_proc = "山治班";
set Addr_proc = "北京市朝陽區";
while i<count do
set name_proc = CONCAT("露西亞",i);
insert into students(Name,Sex,age,class,Addr)values(name_proc,sex_proc,age_proc,class_proc,Addr_proc);
set i = i+1;
end while;
end
$$;
delimiter;
call lucia_proc16(500);
這個就是一個迴圈插入 500 條記錄的 sp 效果如下:
可以在客戶端裡面直接寫 比如用 navicat 就寫:
delimiter $$;
create procedure lucia_proc16(count int)
begin
DECLARE name_proc VARCHAR(20) CHARACTER SET utf8;
DECLARE sex_proc VARCHAR(4) CHARACTER SET utf8;
DECLARE age_proc INT(10);
DECLARE class_proc VARCHAR(20) CHARACTER SET utf8;
DECLARE Addr_proc VARCHAR(50) CHARACTER SET utf8;
DECLARE i INT;
set i = 1;
set sex_proc = "女";
set age_proc = 20;
set class_proc = "山治班";
set Addr_proc = "北京市朝陽區";
while i<count do
set name_proc = CONCAT("露西亞",i);
insert into students(Name,Sex,age,class,Addr)values(name_proc,sex_proc,age_proc,class_proc,Addr_proc);
set i = i+1;
end while;
end
$$;
delimiter;
call lucia_proc16(500);
這個就是一個迴圈插入 500 條記錄的 sp 效果如下: