drop procedure if exists test;
create procedure test()
begin
declare i int; #申明變量
declare count int; #申明變量
set i = 0; #變量賦值
set count=(select count(*) from app_device); #變量賦值
while i <count do #結束循環的條件: 當i大於count時跳出while循環
INSERT INTO `app_device_contact` (`serial_number`, `tel`) VALUES (
(select serial_number from app_device order by device_id asc limit i,1), '3');
set i = i + 1; #循環一次,i加一
end while;
select * from app_device_contact; #查看test表數據
end
call test();
