SQL 漢字轉換拼音首字母

2021-05-22 01:56:23 字數 1398 閱讀 9136

create function whk_fun_getpy(@str nvarchar(4000))

returns nvarchar(4000)

asbegin

declare @word nchar(1),@py nvarchar(4000)

set @py=''

while len(@str)>0

begin

set @word=left(@str,1)

--如果非漢字字元,返回原字元

set @py=@py+(case when unicode(@word) between 19968 and 19968+20901

then (select top 1 py from (

select 'a' as py,n'驁' as word

union all select 'b',n'簿'

union all select 'c',n'錯'

union all select 'd',n'鵽'

union all select 'e',n'樲'

union all select 'f',n'鰒'

union all select 'g',n'腂'

union all select 'h',n'夻'

union all select 'j',n'攈'

union all select 'k',n'穒'

union all select 'l',n'鱳'

union all select 'm',n'旀'

union all select 'n',n'桛'

union all select 'o',n'漚'

union all select 'p',n'曝'

union all select 'q',n'囕'

union all select 'r',n'鶸'

union all select 's',n'蜶'

union all select 't',n'籜'

union all select 'w',n'鶩'

union all select 'x',n'鑂'

union all select 'y',n'韻'

union all select 'z',n'咗'

) t

where word>=@word collate chinese_prc_cs_as_ks_ws

order by py asc) else @word end)

set @str=right(@str,len(@str)-1)

endreturn @py

end--函式呼叫例項:

select dbitrenji_f.whk_fun_getpy('中華人民共和國')

--結果都為:zhrmghg

漢字轉拼音首字母

public string hz2py string hz 獲得漢字的區位碼 else if tmp 45253 tmp 45760 else if tmp 47761 tmp 46317 else if tmp 46318 tmp 46825 else if tmp 46826 tmp 47009...

獲取漢字拼音首字母

有個專案需要用到生成漢字的首字母,但從網上查了一下,對於多音字的處理都不是很好,所以就利用pinyin4j這個工具包自己寫了乙個。用到的jar包是pinyin4j 2.5.0.jar 獲取拼音首字母,多音字用逗號隔開 public static string getfirstspell string...

獲取漢字拼音首字母

unit py inte ce uses sysutils 獲取漢字的拼音首字元,這個函式將用在getpyindexstr 中.function getpyindexchar strchinese string bupcase boolean true char 獲取多個漢字的拼音首字元組成的字串....