本文為大家分享了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('庫名');
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持幫客之家。