当前位置:网站首页>SqlServer 获取字符串中数字,中文及字符部分数据
SqlServer 获取字符串中数字,中文及字符部分数据
2022-06-30 20:37:00 【※※冰馨※※】
--获取英文字符数据
Create function [dbo].[Fun_GetChar]
(
@No varchar(100)
)
RETURNS varchar(100)
AS
BEGIN
WHILE PATINDEX('%[^A-Za-z]%',@No)>0
BEGIN
SET @No=STUFF(@No,PATINDEX('%[^A-Za-z]%',@No),1,'')
END
RETURN CONVERT(varchar(100),@No)
END--select dbo.F_GetChar('2.5mg')--调用函数=mg
--获取数值数据
Create FUNCTION [dbo].[Fun_GetNum]
( @Str NVARCHAR(MAX) )
RETURNS NVARCHAR(MAX)
AS
BEGIN
DECLARE @Start INT;
DECLARE @End INT;
DECLARE @Part NVARCHAR(MAX)
SET @Start = PATINDEX('%[.,0-9]%', @Str);
SET @End = PATINDEX('%[.,0-9]%',SUBSTRING(@Str, @Start+1,LEN(@Str) - @Start));
SET @Part = SUBSTRING(@Str,@Start,1)
WHILE @End >0
BEGIN
SET @Start = @[email protected]
SET @Part = @Part+SUBSTRING(@Str,@Start,1)
SET @End = PATINDEX('%[0-9]%',SUBSTRING(@Str, @Start+1,LEN(@Str) - @Start));
END
RETURN @Part;
END;--seleect dbo.[Fun_GetNumPart]('2.5mg')--调用函数=2.5
--获取中文数据
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 @[email protected][email protected]
set @str=right(@str,len(@str)-1)
end
return @CN
end
GO --select dbo.[Fun_getCN('2.5mg,毫克')--调用函数=毫克
边栏推荐
- By analyzing more than 7million R & D needs, it is found that these eight programming languages are the most needed by the industry
- Lumiprobe生物素亚磷酰胺(羟脯氨酸)说明书
- PM reports work like this, and the boss is willing to give you a raise
- Peking University ACM problems 1006:biorhythms
- MFC界面库BCGControlBar v33.0 - 桌面警报窗口、网格控件升级等
- Solve the problems of Devops landing in complex environment with various tools with full stack and full function solutions
- MySQL简介、详细安装步骤及使用 | 黑马程序员
- Binary search tree (1) - concept and C language implementation
- 亚马逊在阿拉伯联合酋长国限制LGBTQ相关的搜索和产品销售
- 北京大学ACM Problems 1002:487-3279
猜你喜欢

Web APIs 综合案例-Tab栏切换 丨黑马程序员

Lumiprobe蛋白质定量丨QuDye 蛋白定量试剂盒

Wechat applet development practice cloud music
![[1175. prime number arrangement]](/img/f2/d427db03da151786ea1dfb7a76328a.png)
[1175. prime number arrangement]

Testing principle and precautions of biovendor rage ELISA Kit

maya房子建模
![翻转链表II[翻转链表3种方式+dummyHead/头插法/尾插法]](/img/a8/6472e2051a295f5e42a88d64199517.png)
翻转链表II[翻转链表3种方式+dummyHead/头插法/尾插法]

注册设备监理师难考吗,和监理工程师有什么关系?
![Halcon knowledge: check the measurement objects [1]](/img/0a/3a12e281fcb201d8d11b25dac4145a.png)
Halcon knowledge: check the measurement objects [1]

【微服务~Nacos】Nacos之配置中心
随机推荐
树基本概念
Go语学习笔记 - gorm使用 - 数据库配置、表新增 | Web框架Gin(七)
CentOS - enable / disable Oracle
Description of the latest RTSP address rules for Hikvision camera, NVR, streaming media server, playback and streaming [easy to understand]
Peking University ACM problems 1001:exposition
Peking University ACM problems 1006:biorhythms
亚马逊在阿拉伯联合酋长国限制LGBTQ相关的搜索和产品销售
B_QuRT_User_Guide(35)
Dynamic style binding --style and class
Lumiprobe染料酰肼丨BDP FL 酰肼方案
动态样式绑定--style 和 class
学习总结
1、生成对抗网络入门
C file pointer
Implementation principle of PostgreSQL heap table storage engine
Peking University ACM problems 1004:financial management
Go learning notes
Jerry's question about long press boot detection [chapter]
uniapp-路由uni-simple-router
By analyzing more than 7million R & D needs, it is found that these eight programming languages are the most needed by the industry