这个是存储过程
比方说要写一个存储过程,向库里循环插入 500 条记录
存储过程如下:
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 = '初三(2)班'
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 条记录
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)