要求:插入一张表(TESTMV)中三个字段(ID, GROUPID【组id】, USERID【用户id】),为了产生多个组,每个组多个人的数据,进行统计每个组多少人数据用
代码如下:
delete testmv;
create procdedure insertdb()
language SQL
begin
declare v_num int;
declare v_num1 int;
declare v_num2 varchar(12);
set v_num=0;
set v_num1=1;
loop1:
LOOP
if(v_num<100) then
set v_num &#61; v_num &#43;1;
set v_num1&#61;1;
loop2:
LOOP
if(v_num1<&#61;100) then
insert into testmv(ID, GROUPID, USERID) VALUES(&#39;id&#39;||v_num||v_num1, &#39;groupid&#39;||v_num, &#39;userid&#39;||v_num||v_num1);
set v_num1&#61;v_num1&#43;1;
else
leave loop2;
end if;
end loop loop2;
else
leave loop1;
end if;
end loop loop1;
end;
call insertdb();
drop procedure insertdb();