因为很久没写过存储过程了,语法也不记得了,靠百度后,解决了当前问题,这里就简单记录一下。
CREATE PROCEDURE pro1()
BEGIN
DECLARE i int;
DECLARE dbName VARCHAR(40);
SET i = 0;
while i<5 do
SET dbName = concat('table_',i);
set @sqlStr=CONCAT('insert into temp_table SELECT a,b from ',dbName,' WHERE c in ("")');
PREPARE stmt from @sqlStr;
EXECUTE stmt;
set i=i+1;
end while;
END; CALL pro1(); DROP PROCEDURE pro1;