当前位置:网站首页>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,毫克')--调用函数=毫克
边栏推荐
- 数据库 OLAP、OLTP是什么?相同和不同?适用场景
- PHP获取Opcode及C源码
- PHP require/include 区别
- Web host iptables firewall security script
- Binary search tree (1) - concept and C language implementation
- PM reports work like this, and the boss is willing to give you a raise
- 树基本概念
- centos——开启/关闭oracle
- Testing principle and precautions of biovendor rage ELISA Kit
- 请指教在线开户需要什么银行卡?另外想问,现在在线开户安全么?
猜你喜欢

B_QuRT_User_Guide(31)

阿里kube-eventer mysql sink简单使用记录

Evolution of screen display technology

Lumiprobe染料酰肼丨BDP FL 酰肼方案

All the important spark summit features were released here last night (with ultra clear video attached)

uniapp-富文本编辑器

Lumiprobe核酸定量丨QuDye dsDNA BR 检测试剂盒

uniapp-生命周期/路由跳转

Basic concepts of tree

MySQL introduction, detailed installation steps and usage | dark horse programmer
随机推荐
Jenkins can't pull the latest jar package
SQL必需掌握的100个重要知识点:创建和操纵表
Basic components of STL
为什么vscode用久了电脑速度变慢?
Golang应用 ━━ 安装、配置与使用hugo博客系统
断点续传和下载原理分析
19.04 分配器
Description of the latest RTSP address rules for Hikvision camera, NVR, streaming media server, playback and streaming [easy to understand]
判断js对象是否为空的方式
1、生成对抗网络入门
Game 81 biweekly
Playwright - scroll bar operation
On the charm of code language
Analysis of breakpoint continuation and download principle
我想知道股票开户要认识谁?另外,手机开户安全么?
Comparison between QT and other GUI Libraries
Lumiprobe copper free click chemical solution
Lumiprobe nucleic acid quantitative qudye dsDNA br detection kit
Encoding type of Perl conversion file
The newly born robot dog can walk by himself after rolling for an hour. The latest achievement of Wu Enda's first disciple