mysql procedure动态表名

DELIMITER $$

USE `blog`$$

DROP PROCEDURE IF EXISTS `alert_visitlog`$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `alert_visitlog`()
BEGIN
DECLARE i INT;
SET i = 0;
WHILE i < 1000 DO
SET @tab_name = CONCAT('visit_log_',i);
SET @tempsql = CONCAT('ALTER TABLE ',@tab_name,' CHANGE url url VARCHAR(1000) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL;');
PREPARE mainStmt FROM @tempsql;
EXECUTE mainStmt;
SET i = i+1;
END WHILE;
    END$$

DELIMITER ;

你可能感兴趣的:(mysql,Blog,null,table,url,character)