加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

sqlserver提取中文_提取英文_提取数字(函数)

发布时间:2020-12-12 14:05:09 所属栏目:MsSql教程 来源:网络整理
导读:--【提取中文字符】IF OBJECT_ID('dbo.fun_getCN') IS NOT NULLDROP FUNCTION dbo.fun_getCNGOcreate function dbo.fun_getCN(@str varchar(4000)) returns varchar(4000) as begin declare @word nchar(1),@CN varchar(4000) set @CN='' while len(@str)0 b



--【提取中文字符】
IF OBJECT_ID('dbo.fun_getCN') IS NOT NULL
DROP FUNCTION dbo.fun_getCN
GO
create  function  dbo.fun_getCN(@str  varchar(4000))      
returns  varchar(4000)      
as      
begin      
 declare  @word  nchar(1),@CN  varchar(4000)      
 set  @CN=''      
 while  len(@str)>0      
 begin      
	set  @word=left(@str,1)      
	if unicode(@word)  between  19968  and  40869  
		set  @CN=@CN+@word  
	set  @str=right(@str,len(@str)-1)      
 end      
 return  @CN      
end      
GO
  
select dbo.fun_getCN('123我KK哈哈45')  
--中国


select unicode('一')
select unicode('龥')

unicode中文编码范围:19968~40869
参考 http://www.uni-graz.at/~vollmanr/unicode/uni_chinese.html



--【提取中文】
IF OBJECT_ID('DBO.get_Chinese') IS NOT NULL
DROP FUNCTION DBO.get_Chinese
GO
CREATE FUNCTION DBO.get_Chinese(@S NVARCHAR(100))
RETURNS VARCHAR(100)
AS
BEGIN
 WHILE PATINDEX('%[^吖-座]%',@S) > 0
 SET @S = STUFF(@S,PATINDEX('%[^吖-座]%',@S),1,N'')
 RETURN @S
END
GO
select DBO.get_Chinese('123我KK哈哈45')



--【提取数字】
IF OBJECT_ID('dbo.GET_NUMBER2') IS NOT NULL
DROP FUNCTION dbo.GET_NUMBER2
GO
CREATE FUNCTION dbo.GET_NUMBER2(@S VARCHAR(100))
RETURNS VARCHAR(100)
AS
BEGIN
 WHILE PATINDEX('%[^0-9]%',@S) > 0
 BEGIN
	set @s=stuff(@s,patindex('%[^0-9]%',@s),'')
 END
 RETURN @S
END
GO

select dbo.GET_NUMBER2('123我KK哈哈45')


--【提取英文】
IF OBJECT_ID('DBO.get_English') IS NOT NULL
DROP FUNCTION DBO.get_English
GO
CREATE FUNCTION DBO.get_English(@S VARCHAR(100))
RETURNS VARCHAR(100)
AS
BEGIN
 WHILE PATINDEX('%[^a-z]%',patindex('%[^a-z]%','')
 END
 RETURN @S
END
GO

SELECT DBO.get_English('123我KK哈哈45')


(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读