25 lines
1.8 KiB
SQL
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

create function getPY(in_string varchar(32767)) returns mediumtext
BEGIN
DECLARE tmp_str VARCHAR(32767) charset gbk DEFAULT '' ; #in_string值
DECLARE tmp_len SMALLINT DEFAULT 0;#tmp_str的长度
DECLARE tmp_char VARCHAR(2) charset gbk DEFAULT '';# left(tmp_str,1)
DECLARE tmp_rs VARCHAR(32767) charset gbk DEFAULT '';#
DECLARE tmp_cc VARCHAR(2) charset gbk DEFAULT '';#
SET tmp_str = in_string;#in_string赋给tmp_str
SET tmp_len = LENGTH(tmp_str);#
WHILE tmp_len > 0 DO #tmp_str长度大于0则进入该while
SET tmp_char = LEFT(tmp_str,1);#tmp_str最左端的首个字符
SET tmp_cc = tmp_char;#
IF LENGTH(tmp_char)>1 THEN#
SELECT ELT(INTERVAL(CONV(HEX(tmp_char),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),
'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; #
END IF;
SET tmp_rs = CONCAT(tmp_rs,tmp_cc);#tmp_str左端首个字符拼音首字符与返回字符串拼接
SET tmp_str = SUBSTRING(tmp_str,2);#tmp_str左端首字符去除
SET tmp_len = LENGTH(tmp_str);#
END WHILE;
RETURN tmp_rs;#
END;