mysql获取拼音首字母(改进版)
- DELIMITER $$
- USE `test`$$
- DROP FUNCTION IF EXISTS `getPY`$$
- CREATE FUNCTION `getpy`(in_string VARCHAR(255)) RETURNS VARCHAR(255) CHARSET utf8
- BEGIN
- DECLARE tmp_str VARCHAR(255) CHARSET utf8 DEFAULT '';
- DECLARE str_len SMALLINT DEFAULT 0;
- DECLARE tem_loc SMALLINT DEFAULT 0;
- DECLARE tmp_char VARCHAR(10) CHARSET utf8 DEFAULT '';
- DECLARE tmp_len SMALLINT DEFAULT 0;
- DECLARE tmp_rs VARCHAR(255) CHARSET utf8 DEFAULT '';
- DECLARE tmp_cc VARCHAR(10) CHARSET utf8 DEFAULT '';
- SET tmp_str = in_string;
- SET str_len = LENGTH(tmp_str);
- WHILE str_len > 0 DO
- SET tmp_char = LEFT(tmp_str,1);
- SET tmp_cc = tmp_char;
- IF LENGTH(tmp_char) > 1
- THEN
- SET tem_loc = INTERVAL(CONV(HEX(CONVERT(tmp_char USING gbk)),16,10),0xB0A1,0xB0C5,0xB2C1,0xB4EE,0xB6EA,0xB7A2,0xB8C1,0xB9FE,0xBBF7,0xBFA6,0xC0AC,0xC2E8,0xC4C3,0xC5B6,0xC5BE,0xC6DA,0xC8BB,0xC8F6,0xCBFA,0xCDDA,0xCEF4,0xD1B9,0xD4D1);
- IF (tem_loc>0 AND tem_loc < 24 )
- THEN
- SELECT ELT(tem_loc, 'A','B','C','D','E','F','G','H','J','K','L','M','N','O','P','Q','R','S','T','W','X','Y','Z') INTO tmp_cc;
- ELSE
- SET tmp_cc = '';
- END IF;
- END IF;
- SET tmp_rs = CONCAT(tmp_rs,tmp_cc);
- SET tmp_len = CHAR_LENGTH(tmp_char) + 1;
- SET tmp_str = SUBSTRING(tmp_str,tmp_len);
- SET str_len = LENGTH(tmp_str);
- END WHILE;
- RETURN tmp_rs;
- END$$
- DELIMITER ;
============ 欢迎各位老板打赏~ ===========
与本文相关的文章
- · docker定时任务Mysql脚本
- · docker安装mysql8注意事项
- · .NET8 Mysql SSL error
- · 定时备份docker中的mysql
- · docker-compose通过容器名连接mysql
- · unity3d mysql error: The given key was not present in the dictionary.
- · MySQL 批量修改数据表编码及字符集
- · Your database must use ‘READ-COMMITTED’ as the default isolation level.
- · MySQL-InnoDB存储引擎
- · 将数据从mysql迁移到clickhouse
- · mysql关于索引那些事儿
- · mysql大数据表加字段改名