mssql sqlserver 获取指定汉字的笔画数的方法分享

本文分享了一个用于计算汉字笔画数的SQL函数实现方法。该函数通过Unicode范围判断是否为汉字,并根据预设的汉字样本返回对应的笔画数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

摘要:
下文讲述计算汉字笔画数的sql函数分享,如下所示:



例:建立汉字笔画数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

 

转载于:https://www.cnblogs.com/lairui1232000/p/9410432.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值