当前位置:网站首页>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,毫克')--调用函数=毫克
边栏推荐
- 片荒吗?不用下载直接在线免费看的资源来了!2022年收藏夹必须有它!
- 偏向锁/轻量锁/重级锁锁锁更健康,上锁解锁到底是怎么完成实现的
- AVL balanced binary tree (I) - concept and C language implementation
- Black apple server system installation tutorial, black apple installation tutorial, teach you how to install black apple in detail [easy to understand]
- Summary of PHP file upload (garbled code, move failure, permission, display picture)
- Document contains & conditional competition
- 数据库 OLAP、OLTP是什么?相同和不同?适用场景
- On the charm of code language
- uniapp-路由uni-simple-router
- 基于开源流批一体数据同步引擎ChunJun数据还原—DDL解析模块的实战分享
猜你喜欢
Lumiprobe cell biology - dia, instructions for lipophilic tracer
CentOS - enable / disable Oracle
【数字IC应届生职业规划】Chap.1 IC行业产业链概述及代表企业大厂汇总
SQL优化
Implementation principle of PostgreSQL heap table storage engine
Vite2兼容低版本chrome(如搜狗80),通过polyfills处理部分需求高版本的语法
Lumiprobe dye hydrazide - BDP FL hydrazide solution
Lvalue reference and lvalue reference
Huffman tree (I) basic concept and C language implementation
1、生成对抗网络入门
随机推荐
Lumiprobe生物素亚磷酰胺(羟脯氨酸)说明书
MFC界面库BCGControlBar v33.0 - 桌面警报窗口、网格控件升级等
maya房子建模
Evolution of screen display technology
阿里kube-eventer mysql sink简单使用记录
数据库 OLAP、OLTP是什么?相同和不同?适用场景
在线教育项目用户登录和注册
Lumiprobe蛋白质定量丨QuDye 蛋白定量试剂盒
Go learning notes
MySQL:SQL概述及数据库系统介绍 | 黑马程序员
No "history of blood and tears" in home office | community essay solicitation
B_QuRT_User_Guide(31)
北京大学ACM Problems 1002:487-3279
Peking University ACM problems 1005:i think I need a houseboat
二叉查找树(一) - 概念与C语言实现
Web host iptables firewall security script
NLP paper lead reading | what about the degradation of text generation model? Simctg tells you the answer
片荒吗?不用下载直接在线免费看的资源来了!2022年收藏夹必须有它!
19.04 分配器
STL的基本组成部分