漢字首字母查詢處理使用者定義函式
create function f_getpy1(@str nvarchar(4000))
returns nvarchar(4000)
asbegin
declare @py table(
ch char(1),
hz1 nchar(1) collate chinese_prc_cs_as_ks_ws,
hz2 nchar(1) collate chinese_prc_cs_as_ks_ws)
insert @py select 'a',n'吖',n'鏊'
union all select 'b',n'八',n'簿'
union all select 'c',n'嚓',n'錯'
union all select 'd',n'噠',n'跺'
union all select 'e',n'屙',n'貳'
union all select 'f',n'發',n'馥'
union all select 'g',n'旮',n'過'
union all select 'h',n'鉿',n'蠖'
union all select 'j',n'丌',n'竣'
union all select 'k',n'咔',n'廓'
union all select 'l',n'垃',n'雒'
union all select 'm',n'媽',n'穆'
union all select 'n',n'拿',n'糯'
union all select 'o',n'噢',n'漚'
union all select 'p',n'趴',n'曝'
union all select 'q',n'七',n'群'
union all select 'r',n'蚺',n'箬'
union all select 's',n'仨',n'鎖'
union all select 't',n'他',n'籜'
union all select 'w',n'哇',n'鋈'
union all select 'x',n'夕',n'蕈'
union all select 'y',n'丫',n'蘊'
union all select 'z',n'匝',n'做'
declare @i int
set @i=patindex('%[吖-做]%' collate chinese_prc_cs_as_ks_ws,@str)
while @i>0
select @str=replace(@str,substring(@str,@i,1),ch)
,@i=patindex('%[吖-做]%' collate chinese_prc_cs_as_ks_ws,@str)
from @py
where substring(@str,@i,1) between hz1 and hz2
return(@str)
endgo
ex:select * from tablename dbo.f_getpy1(name) like '%wpp%'
sql 取漢字首字母
create function fn getpy str nvarchar 4000 returns nvarchar 4000 用於加密 with encryption asbegin declare intlen intdeclare strret nvarchar 4000 declare t...
漢字首字母
在很多軟體中,輸入拼音的首寫字母就可以快速定位到某個詞條。比如,在鐵路售票軟體中,輸入 bj 就可以定位到 北京 怎樣在自己的軟體中實現這個功能呢?問題的關鍵在於 對每個漢字必須能計算出它的拼音首字母。gb2312漢字編碼方式中,一級漢字的3755個是按照拼音順序排列的。我們可以利用這個特徵,對常用...
mysql實現漢字首字母查詢
建立拼音函式 建立拼音函式drop function ifexists getpy create function getpy in string varchar 21845 returns varchar 21845 charset utf8 begin 擷取字串,每次做擷取後的字串存放在該變數中...