CREATE OR REPLACE FUNCTION "F_SPELLCN" (P1 VARCHAR2,P2 INT default 0) return VARCHAR2 as
/*
* 获得汉字拼音首字母
* 入口参数:汉字字符串、是否只取第一个汉字的拼音首字母
*/
CHAR1 VARCHAR2(2);
CHAR2 VARCHAR2(2);
LEN INTEGER;
N1 INTEGER;
N2 INTEGER;
CSOUND VARCHAR2(32767);
BEGIN
if p1 is null then
return '';
end if;
IF P2 = 1 THEN
LEN := 1;
ELSE
LEN := LENGTH(P1);
END IF;
if LEN=0 then
return '';
end if;
FOR I IN 1..LEN LOOP
CHAR2 := SUBSTR(P1, i, 1);
N1 := FLOOR(ASCII(CHAR2) / 256);
N2 := MOD(ASCII(CHAR2), 256);
IF N1 = 0 AND N2 <= 129 THEN
CHAR1 := CHAR2;
ELSIF N2 <> 127 AND N2 <> 255 AND NOT (N2 >= 0 AND N2 <= 63) THEN
SELECT
CASE
WHEN CHAR2 >= '丂' AND CHAR2 < '芭' THEN 'A'
WHEN CHAR2 >= '芭' AND CHAR2 < '擦' THEN 'B'
WHEN CHAR2 >= '擦' AND CHAR2 < '搭' THEN 'C'
WHEN CHAR2 >= '搭' AND CHAR2 < '蛾' THEN 'D'
WHEN CHAR2 >= '蛾' AND CHAR2 < '发' THEN 'E'
WHEN CHAR2 >= '发' AND CHAR2 < '噶' THEN 'F'
WHEN CHAR2 >= '噶' AND CHAR2 < '哈' THEN 'G'
WHEN CHAR2 >= '哈' AND CHAR2 < '击' THEN 'H'
WHEN CHAR2 >= '击' AND CHAR2 < '喀' THEN 'J'
WHEN CHAR2 >= '喀' AND CHAR2 < '垃' THEN 'K'
WHEN CHAR2 >= '垃' AND CHAR2 < '妈' THEN 'L'
WHEN CHAR2 >= '妈' AND CHAR2 < '拿' THEN 'M'
WHEN CHAR2 >= '拿' AND CHAR2 < '哦' THEN 'N'
WHEN CHAR2 >= '哦' AND CHAR2 < '啪' THEN 'O'
WHEN CHAR2 >= '啪' AND CHAR2 < '期' THEN 'P'
WHEN CHAR2 >= '期' AND CHAR2 < '然' THEN 'Q'
WHEN CHAR2 >= '然' AND CHAR2 < '撒' THEN 'R'
WHEN CHAR2 >= '撒' AND CHAR2 < '塌' THEN 'S'
WHEN CHAR2 >= '塌' AND CHAR2 < '挖' THEN 'T'
WHEN CHAR2 >= '挖' AND CHAR2 < '稀' THEN 'W'
WHEN CHAR2 >= '稀' AND CHAR2 < '压' THEN 'X'
WHEN CHAR2 >= '压' AND CHAR2 < '匝' THEN 'Y'
WHEN CHAR2 >= '匝' AND CHAR2 <= '鼱' THEN 'Z'
END
INTO CHAR1
FROM DUAL;
ELSE
CHAR1 := 'ER';
END IF;
CSOUND := CSOUND || CHAR1;
END LOOP;
RETURN CSOUND;
END;
/*
* 获得汉字拼音首字母
* 入口参数:汉字字符串、是否只取第一个汉字的拼音首字母
*/
CHAR1 VARCHAR2(2);
CHAR2 VARCHAR2(2);
LEN INTEGER;
N1 INTEGER;
N2 INTEGER;
CSOUND VARCHAR2(32767);
BEGIN
if p1 is null then
return '';
end if;
IF P2 = 1 THEN
LEN := 1;
ELSE
LEN := LENGTH(P1);
END IF;
if LEN=0 then
return '';
end if;
FOR I IN 1..LEN LOOP
CHAR2 := SUBSTR(P1, i, 1);
N1 := FLOOR(ASCII(CHAR2) / 256);
N2 := MOD(ASCII(CHAR2), 256);
IF N1 = 0 AND N2 <= 129 THEN
CHAR1 := CHAR2;
ELSIF N2 <> 127 AND N2 <> 255 AND NOT (N2 >= 0 AND N2 <= 63) THEN
SELECT
CASE
WHEN CHAR2 >= '丂' AND CHAR2 < '芭' THEN 'A'
WHEN CHAR2 >= '芭' AND CHAR2 < '擦' THEN 'B'
WHEN CHAR2 >= '擦' AND CHAR2 < '搭' THEN 'C'
WHEN CHAR2 >= '搭' AND CHAR2 < '蛾' THEN 'D'
WHEN CHAR2 >= '蛾' AND CHAR2 < '发' THEN 'E'
WHEN CHAR2 >= '发' AND CHAR2 < '噶' THEN 'F'
WHEN CHAR2 >= '噶' AND CHAR2 < '哈' THEN 'G'
WHEN CHAR2 >= '哈' AND CHAR2 < '击' THEN 'H'
WHEN CHAR2 >= '击' AND CHAR2 < '喀' THEN 'J'
WHEN CHAR2 >= '喀' AND CHAR2 < '垃' THEN 'K'
WHEN CHAR2 >= '垃' AND CHAR2 < '妈' THEN 'L'
WHEN CHAR2 >= '妈' AND CHAR2 < '拿' THEN 'M'
WHEN CHAR2 >= '拿' AND CHAR2 < '哦' THEN 'N'
WHEN CHAR2 >= '哦' AND CHAR2 < '啪' THEN 'O'
WHEN CHAR2 >= '啪' AND CHAR2 < '期' THEN 'P'
WHEN CHAR2 >= '期' AND CHAR2 < '然' THEN 'Q'
WHEN CHAR2 >= '然' AND CHAR2 < '撒' THEN 'R'
WHEN CHAR2 >= '撒' AND CHAR2 < '塌' THEN 'S'
WHEN CHAR2 >= '塌' AND CHAR2 < '挖' THEN 'T'
WHEN CHAR2 >= '挖' AND CHAR2 < '稀' THEN 'W'
WHEN CHAR2 >= '稀' AND CHAR2 < '压' THEN 'X'
WHEN CHAR2 >= '压' AND CHAR2 < '匝' THEN 'Y'
WHEN CHAR2 >= '匝' AND CHAR2 <= '鼱' THEN 'Z'
END
INTO CHAR1
FROM DUAL;
ELSE
CHAR1 := 'ER';
END IF;
CSOUND := CSOUND || CHAR1;
END LOOP;
RETURN CSOUND;
END;