记录不长使用,但是有用的sql
1. 获取字符串的字符首字母
show variables like 'log_bin_trust_function_creators';
-- 必须开启
set global log_bin_trust_function_creators=1;
DELIMITER //
CREATE FUNCTION to_simple_spelle(in_string VARCHAR(100))
RETURNS VARCHAR(100)
BEGIN
DECLARE str_length INT;
DECLARE char_code VARCHAR(1);
DECLARE code_index INT DEFAULT 0;
DECLARE i INT DEFAULT 1;
DECLARE simple_spelle VARCHAR(100) DEFAULT '';
SET str_length = CHAR_LENGTH(in_string);
WHILE i <= str_length DO
SET char_code = SUBSTR(in_string, i, 1);
SET code_index = INTERVAL(CONV(HEX(CONVERT(LEFT(char_code, 1) 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 code_index > 0 AND code_index < 24 THEN
SET simple_spelle = CONCAT(simple_spelle, ELT(code_index, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'W', 'X', 'Y', 'Z'));
END IF;
SET i = i + 1;
END WHILE;
RETURN simple_spelle;
END//
DELIMITER ;