One. Fristpinyin: This function converts the first character of a Chinese string into a phonetic alphabet (for example: "Chinese"->z)
CREATE FUNCTION' Fristpinyin ' (p_nameVARCHAR(255))RETURNS varchar(255) CHARSET UTF8BEGIN DECLAREV_returnVARCHAR(255); SETV_return=ELT (INTERVAL (CONV (HEX ( Left(CONVERT(P_name USING GBK),1)), -,Ten), 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'); RETURNV_return;END
two. Pinyin: This function is to connect a Chinese string to each phonetic parent (for example: "Chinese"->zgr)
CREATE FUNCTION' Pinyin ' (p_nameVARCHAR(255))RETURNS varchar(255) CHARSET UTF8BEGIN DECLAREV_compareVARCHAR(255); DECLAREV_returnVARCHAR(255); DECLAREIINT; SETI= 1; SETV_return= "'; whileI<LENGTH (p_name) doSETV_compare=SUBSTR (P_name, I,1); IF(V_compare!= "') Then #SETV_return=CONCAT (V_return,',', V_compare); SETV_return=CONCAT (V_return, Fristpinyin (V_compare)); #SETV_return=Fristpinyin (V_compare); END IF; SETI=I+ 1; End while; IF(ISNULL(V_return)orV_return= "') Then SETV_return=P_name; END IF; RETURNV_return;END
Example:
Mysql> Select P.province, Fristpinyin (p.province), pinyin (P.province) from province p;
+------------------+-------------------------+--------------------+
| Province | Fristpinyin (p.province) | Pinyin (p.province) |
+------------------+-------------------------+--------------------+
| Beijing | B | BJS |
| Tianjin, China | T | TJS |
| Hebei Province | H | HBS |
| Shanxi Province | S | SXS |
| Inner Mongolia | N | Nmgzzq |
+------------------+-------------------------+--------------------+
5 rows in Set
MySQL Kanji to Pinyin