MYSQL将表名称修改成大写的存储过程
程序员文章站
2023-12-22 10:48:28
本文为大家分享了mysql将表名称修改成大写的存储过程,具体内容如下
1. 条件:
1.1 mysql设置对大小写敏感
2. 执行下述存储过程: ...
本文为大家分享了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('库名');
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。