CREATE DEFINER=root
@localhost
PROCEDURE pro_syncdata
()
BEGIN
declare icount int default 0;
declare pageSize int default 10;
declare pageIndex int default 0;
declare pageCount int default 0;
declare maxid int default 0;
select count(id) into icount from tbl_test;
if mod(icount,pageSize)=0 then
set pageCount = icount div pageSize;
ELSE
set pageCount = icount div pageSize +1;
end if;
while pageIndex<pageCount DO
insert into tbl_test_copy(testid,testname)
select id,`name` from tbl_test where id >maxid order by id limit 10;
select max(id) into maxid from (select id,`name` from tbl_test where id >maxid order by id limit 10) t;
set pageIndex = pageIndex + 1;
end while;
END