欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

Mysql数据库表名批量改为大写_MySQL

程序员文章站 2022-04-08 22:10:03
...
bitsCN.com

Mysql数据库表名批量改为大写

[sql] DELIMITER //     DROP PROCEDURE IF EXISTS uppercase //     CREATE PROCEDURE uppercase(IN dbname VARCHAR(200))     BEGIN     DECLARE done INT DEFAULT 0;     DECLARE oldname VARCHAR(200);     DECLARE cur CURSOR FOR SELECT table_name FROM information_schema.TABLES WHERE table_schema = dbname;     DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;     OPEN cur;     REPEAT     FETCH cur INTO oldname;     SET @newname = UPPER(oldname);     #IF newname equals to oldname, do nothing;   #select 'a'  'A'; -> 0   #select 'a'  BINARY 'A'; -> 1   SET @isNotSame = @newname  BINARY oldname;     IF NOT done && @isNotSame THEN     SET @SQL = CONCAT('rename table ',oldname,' to ',@newname);     PREPARE tmpstmt FROM @SQL;     EXECUTE tmpstmt;     DEALLOCATE PREPARE tmpstmt;     END IF;     UNTIL done END REPEAT;     CLOSE cur;     END //     DELIMITER ;   #调用存储过程  #call uppercase('数据库名');  #  


bitsCN.com
相关标签: 数据库表