mysql 存储过程
CREATE PROCEDURE new111(in tableane VARCHAR(20)) BEGIN declare i int default 1; myloop:loop set @rid = tableane; SET @pdd1 = concat('CREATE TABLE ',@rid,' LIKE user', i); SET @pdd2 = concat('INSERT INTO ',@rid,' SELECT * FROM user', i); SET @pdd3 = concat('DELETE from user', i); PREPARE pdd1 FROM @pdd1; EXECUTE pdd1; PREPARE pdd2 FROM @pdd2; EXECUTE pdd2; PREPARE pdd3 FROM @pdd3; EXECUTE pdd3; set i=i+1; if i>5 then leave myloop; end if; end loop myloop; END
varchar 类型必须指定长度