Z)CREATE FUNCTION `fristPinyin`(P_NAME VARCHAR(255)) RETURNS varchar(2">
时间:2021-07-01 10:21:17 帮助过:44人阅读
SET I = 1;
SET V_RETURN = '';
while I < LENGTH(P_NAME) do
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
示例:
mysql> select p.province, fristPinyin(p.province), pinyin(p.province) from province p;
+------------------+-------------------------+--------------------+
| province | fristPinyin(p.province) | pinyin(p.province) |
+------------------+-------------------------+--------------------+
| 北京市 | B | BJS |
| 天津市 | T | TJS |
| 河北省 | H | HBS |
| 山西省 | S | SXS |
| 内蒙古自治区 | N | NMGZZQ |
+------------------+-------------------------+--------------------+
5 rows in set