Oracle獲取拼音碼函式

2021-06-09 17:45:30 字數 2148 閱讀 6370

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'

endinto char1

from dual;

else

char1 := 'er';

end if;

csound := csound || char1;

end loop;

return csound;

end;

獲取拼音碼 sql函式

create function dbo f util getpinyincode str nvarchar 4000 returns nvarchar 4000 asbegin declare word nchar 1 py nvarchar 4000 set py while len str 0 ...

sql函式 漢字拼音碼

create or replace function to piny p name in varchar2 return varchar2 as v compare varchar2 100 v return varchar2 4000 function f nlssort p word in va...

C 取拼音碼

取拼音碼 using system using system.collections.generic using system.text namespace sunhotel static public string getchinesespell string strtext return mys...