mysql表名批量修改为大/小写

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 = LOWER(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('test1');
#test1为你想要修改的数据库的名称

 

UPPER(str)

返回字符串str,根据当前字符集映射的所有字符修改为大写。

LOWER(str)

返回根据当前字符集映射所有字符改变为小写,即返回小写的字符串。

 

上一篇:项目中遇到的问题-mysql执行定时器任务


下一篇:python下pip的安装