MySQL while taking out Chinese character string first letter stored procedure (not distinguishing polyphone)

Source: Internet
Author: User

--Pinyin returns the entire character string with all initial letters

BEGIN
DECLARE v_compare VARCHAR (255);
DECLARE V_return VARCHAR (255);
DECLARE I INT;
SET I = 1;
SET V_return = ';
While I < LENGTH (P_name) does
SET V_compare = SUBSTR (P_name, I, 1);
IF (V_compare! = ") Then
#SET V_return = CONCAT (V_return, ', ', v_compare);
SET V_return = CONCAT (V_return, Fristpinyin (V_compare));
#SET V_return = Fristpinyin (V_compare);
END IF;
SET i = i + 1;
End while;
IF (ISNULL (v_return) or V_return = ") Then
SET V_return = p_name;
END IF;
RETURN V_return;
END

--Fristpinyin take out the first letter of a single character

BEGIN
DECLARE V_return VARCHAR (255);
SET V_return = ELT (INTERVAL (CONV (HEX (Left (CONVERT (p_name USING GBK), 1), 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 ');
RETURN V_return;
END

MySQL while taking out Chinese character string first letter stored procedure (not distinguishing polyphone)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.