漢子轉拼音碼SQL指令碼函式

2021-10-12 20:07:58 字數 1654 閱讀 7701

--漢子取拼音首字母

use [cisdb_pzhyy]

go/****** object:  userdefinedfunction [dbo].[fun_getpy]    script date: 12/25/2020 10:26:28 ******/

set ansi_nulls on

goset quoted_identifier on

goalter function [dbo].[fun_getpy](@str nvarchar(4000)) 

returns nvarchar(4000) 

as begin 

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) 

end 

return @py 

end 

使用select dbo.fun_getpy('中華人民共和國'),dbo.get_wbm('中華人民共和國') 

*/

獲取拼音碼 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...

Oracle獲取拼音碼函式

create or replace function f spellcn p1 varchar2,p2 int default 0 return varchar2 as 獲得漢字拼音首字母 入口引數 漢字字串 是否只取第乙個漢字的拼音首字母 char1 varchar2 2 char2 varcha...