Home > database >  The mysql database to accurately obtain han phonetics pinyin initials?
The mysql database to accurately obtain han phonetics pinyin initials?

Time:09-22

Mysql database version 5.7, need to use pinyin initials, created the first pinyin initials extract function, but through the function to extract the first letter, some words of pinyin initials extraction error, such as "xin", "yan", "Ou" and so on these initials extraction for "Z",

Character set after the search, show variables like '% collation %') And the results are as follows:
Collation_connection=utf8_general_ci
Collation_database=utf8_general_ci
Collation_server=utf8mb4_unicode_ci
=======================

Pinyin initials extraction function code is as follows:

ELIMITER $$

The CREATE

The FUNCTION ` database name `. ` GET_FIRST_PINYIN_CHAR_1 ` (PARAM VARCHAR (255)) RETURNS a VARCHAR (2) the CHARSET utf8

The BEGIN
DECLARE V_RETURN VARCHAR (255);
DECLARE V_FIRST_CHAR VARCHAR (2);
The SET V_FIRST_CHAR=UPPER (LEFT (PARAM, 1));
The SET V_RETURN=V_FIRST_CHAR;
IF LENGTH (V_FIRST_CHAR) & lt;> CHARACTER_LENGTH (V_FIRST_CHAR) THEN
The SET V_RETURN=ELT (INTERVAL (CONV (HEX (LEFT (the CONVERT (PARAM USING GBK), 1)), 16, 18),
Xb2c1 xb0a1 0, 0 xb0c5, 0, 0 xb4ee, 0 xb6ea, 0 xb7a2, 0 xb8c1, 0 xb9fe, 0 xbbf7,
Xc2e8 xbfa6 0, 0 xc0ac, 0, 0 xc4c3, 0 xc5b6, 0 xc5be, 0 xc6da, 0 xc8bb,
Xcdda xc8f6 0, 0 xcbfa, 0, 0 xcef4, 0 xd1b9, 0 xd4d1),
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J' and 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'W', 'X', 'Y', 'Z');
END IF;
RETURN V_RETURN;
END $$

DELIMITER.
========================
Pinyin initials extract mention test
The SELECT get_first_pinyin_char_1 (" xin ");

The results for "Z"
Correct the result should be "X"

Consult everybody, how should solve?
  • Related