MYSQL存储过程中 使用变量 做表名
以下是完整的例子,全复制粘贴即可
DELIMITER $$
DROP PROCEDURE IF EXISTS `test`$$
CREATE
/*[DEFINER = { user | CURRENT_USER }]*/
PROCEDURE `wx`.`test`()
BEGIN
-- DECLARE dbName VARCHAR(30);
SET @dbName = 'aaa';
SET @STMT =CONCAT("CREATE TABLE ",@dbName," SELECT id from wtp_votoresult_20170919;");
PREPARE STMT1 FROM @STMT;
EXECUTE STMT1;
END$$
DELIMITER ;