MYSQL將表稱號修正成年夜寫的存儲進程。本站提示廣大學習愛好者:(MYSQL將表稱號修正成年夜寫的存儲進程)文章只能為提供參考,不一定能成為您想要的結果。以下是MYSQL將表稱號修正成年夜寫的存儲進程正文
本文為年夜家分享了MYSQL將表稱號修正成年夜寫的存儲進程,詳細內容以下
1. 前提:
1.1 Mysql設置對年夜小寫敏感
2. 履行下述存儲進程:
#call uppercase('庫名') 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); SET @isNotSame = @newname <> BINARY oldname; IF NOT done && @isNotSame THEN SET @SQL = CONCAT('rename table `',oldname,'` to `', LOWER(@newname), '_tmp` '); PREPARE tmpstmt FROM @SQL; EXECUTE tmpstmt; SET @SQL = CONCAT('rename table `',LOWER(@newname),'_tmp` to `',@newname, '`'); PREPARE tmpstmt FROM @SQL; EXECUTE tmpstmt; DEALLOCATE PREPARE tmpstmt; END IF; UNTIL done END REPEAT; CLOSE cur; END
3. 履行一下語句
call uppercase('庫名');
以上就是本文的全體內容,願望對年夜家的進修有所贊助,也願望年夜家多多支撐。