zoukankan      html  css  js  c++  java
  • 将某个MySQL库中的UTF8字符列都转成GBK格式

    DELIMITER $$

    DROP PROCEDURE IF EXISTS `dba`.`Proc_ChangeCharacter2GBK`$$

    CREATE DEFINER=`root`@`%` PROCEDURE `  Proc_ChangeCharacter2GBK`(in DATABASENAME varchar(20))
    BEGIN
        DECLARE done INT DEFAULT 0;
        DECLARE a VARCHAR(64) DEFAULT '';
        DECLARE b VARCHAR(64) DEFAULT '';
        DECLARE c VARCHAR(64) DEFAULT '';
        DECLARE d VARCHAR(64) DEFAULT '';
        DECLARE l_sql VARCHAR(500);
        
        DECLARE AlterColumnsCharacter CURSOR FOR
               SELECT TABLE_SCHEMA,TABLE_NAME,COLUMN_NAME,COLUMN_TYPE
               FROM information_schema.COLUMNS
               WHERE TABLE_SCHEMA=DATABASENAME
                    and TABLE_NAME in (  SELECT B.TABLE_NAME FROM information_schema.TABLES B
                                                              WHERE B.TABLE_SCHEMA=DATABASENAME  AND B.TABLE_TYPE='BASE TABLE' ) 
                    and COLUMN_TYPE like '%VARCHAR%' and CHARACTER_SET_NAME='utf8' and COLLATION_NAME='utf8_general_ci';

        DECLARE CONTINUE HANDLER FOR NOT FOUND SET done=1;
      
        OPEN AlterColumnsCharacter;
      
        REPEAT  FETCH AlterColumnsCharacter INTO a,b,c,d;

        if(done = 0) then 
          SET l_sql=CONCAT(' alter table ',a, '.',b,' change ',c,' ',c,' ',d,' character set gbk collate gbk_chinese_ci NULL; '); 
          SET @sql=l_sql;
          PREPARE s1 FROM @sql;
          EXECUTE s1;
          DEALLOCATE PREPARE s1;
        end if;
        
       
        UNTIL done 
        END REPEAT;
        CLOSE AlterColumnsCharacter;
        END$$

    DELIMITER ;


  • 相关阅读:
    hdu6007 Mr. Panda and Crystal 最短路+完全背包
    ID生成器的一种可扩展实现方案
    使用PUT方法上传文件无法工作原因分析
    负载均衡算法
    父类和子类属性覆盖的各种情况分析
    java functional syntax overview
    Starter Set of Functional Interfaces
    application/xml和text/xml的区别
    mime type 概要介绍
    spring mvc 详细执行流程
  • 原文地址:https://www.cnblogs.com/keanuyaoo/p/3317994.html
Copyright © 2011-2022 走看看