本文为大家分享了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('库名');

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com