我想创建程序以使用limit
选项insert into
.. with select
.. 或create table as select
.....
我想limit
一次只插入 50 万条记录,所以我使用 while 循环,这次我设置了 count3,因为我试图插入 150 万条记录。
call proc1( with long sql statement......................)
DELIMITER //
CREATE PROCEDURE proc1(IN sqllines text)
BEGIN
DECLARE valFrom INT;
DECLARE valTo INT;
DECLARE count INt default 0;
SET @sqlin = sqllines;
SET valFrom = 0;
SET valTo = 500000;
SET @sql = ('@sqlin LIMIT valFrom , valTo');
WHILE count < 3
DO
PREPARE stmt from @sql;
EXECUTE stmt;
SET valFrom = valFrom+500000;
SET valTo = valTo+500000;
set count = count + 1;
END WHILE;
END;
//
DELIMITER ;