mssql sqlserver 获取钦命汉字的笔画数的方法分享

发布时间:2019-11-10  栏目:NoSQL  评论:0 Comments

转自:http://www.maomao365.com/?p=6421

转自:http://www.maomao365.com/?p=6410

摘要:

摘要:

下文呈报总计汉字笔画数的sql函数分享,如下所示:

下文主要分享从钦定字符串或列中拿到数字音信,如下所示:
试生势况:sql server 二零零四


----编写sql函数
    create function getShuZi(@tmp nvarchar(800))
    returns nvarchar(800)
    as 
    begin
          while PATINDEX('%[^0-9]%', @tmp) > 0  
           begin  
             set @tmp = STUFF(@tmp, PATINDEX('%[^0-9]%', @tmp), 1, '');  
           end;  
           return @tmp;   
    end
    go
   ----测试sql函数
   SELECT dbo.getShuZi('猫猫小屋maomao365.com-sql教程专用网站')   
   go
   drop function dbo.getShuZi
   go

例:组建汉字笔划数sql函数 

 

create function [dbo].[fn_hanZiBiHuaShu](@char nchar(2)) 
returns int 
as 
begin 
return( 
case when unicode(@char) between 19968 and 40869 then( 
select top 1 id from( 
select id=1,ch=N'亅' 
union all select 2,N'阝' 
union all select 3,N'马' 
union all select 4,N'风' 
union all select 5,N'龙' 
union all select 6,N'齐' 
union all select 7,N'龟' 
union all select 8,N'齿' 
union all select 9,N'鸩' 
union all select 10,N'龀' 
union all select 11,N'龛' 
union all select 12,N'龂' 
union all select 13,N'龆' 
union all select 14,N'龈' 
union all select 15,N'龊' 
union all select 16,N'龍' 
union all select 17,N'龠' 
union all select 18,N'龎' 
union all select 19,N'龐' 
union all select 20,N'龑' 
union all select 21,N'龡' 
union all select 22,N'龢' 
union all select 23,N'龝' 
union all select 24,N'齹' 
union all select 25,N'龣' 
union all select 26,N'龥' 
union all select 27,N'齈' 
union all select 28,N'龞' 
union all select 29,N'麷' 
union all select 30,N'鸞' 
union all select 31,N'麣' 
union all select 32,N'龖' 
union all select 33,N'龗' 
union all select 35,N'齾' 
union all select 36,N'齉' 
union all select 39,N'靐' 
union all select 64,N'龘' 
)a where ch>=@char collate Chinese_PRC_Stroke_CS_AS_KS_WS 
order by id ASC) 
else 0 end) 
end

go

--测试获取汉字笔画数的sql函数 
select dbo.[fn_hanZiBiHuaShu]('猫')

drop function dbo.[fn_hanZiBiHuaShu]
go

 

留下评论

网站地图xml地图