mysql怎么用sql语句创建存储过程
2个回答
展开全部
可以在客户端里面直接写 比如用 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 效果如下:
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询