当前位置:网站首页>SQL implements split
SQL implements split
2022-07-04 16:40:00 【Full stack programmer webmaster】
create function [dbo].[Get_StrArrayLength] ( @str varchar(max), – String to split @split varchar(10) – Separator symbol ) returns int as begin declare @location int declare @start int declare @length int – Remove space before and after set @str=ltrim(rtrim(@str)) – Where the separator first appears set @location=charindex(@split,@str) – Set the length of the separated string to 1 set @length=1
while @location<>0 begin set @[email protected]+1 set @location=charindex(@split,@str,@start) set @[email protected]+1 end return @length end
drop function [dbo].[Get_StrArrayStrOfIndex] go create function [dbo].[Get_StrArrayStrOfIndex] ( @str varchar(max), – String to split @split varchar(10), – Separator symbol @index int – Take the first few elements ) returns varchar(1024) as begin declare @location int declare @start int declare @next int declare @seed int declare @pos int if @index<=0 return ” set @str=ltrim(rtrim(@str)) set @start=1 set @next=1 set @pos=1 set @seed=len(@split) set @location=charindex(@split,@str) while @location<>0 and @index>@next and @pos<@index begin set @[email protected][email protected] set @location=charindex(@split,@str,@start) set @[email protected]+1 set @[email protected]+1 end if @location =0 if @pos<>@index return ” else select @location =len(@str)+1 – There are two situations :1、 There is no delimiter in the string 2、 There is a separator in the string , Jump out of while After the cycle ,@location by 0, The default is that there is a separator after the string . return substring(@str,@start,@[email protected]) end
declare @id varchar(30) select @id=dbo.Get_StrArrayStrOfIndex(‘4321,2223,333,5554′,’,’,2)
My improved version , Iconicity Hashtable Same visit
drop function [dbo].[Get_ArrayStrOfName] Go
create function [dbo].[Get_ArrayStrOfName] ( @str varchar(5000), – String to split @split varchar(1), – Separator symbol @itemSplit varchar(1), – Element separator @item varchar(20) – Which element to take ) returns varchar(1024) As Begin declare @location int – Find the position of the substring declare @tempItem varchar(50) – Current item declare @tempItemName varchar(20) – The name of the current item set @str=ltrim(rtrim(@str)) set @tempItem=” set @tempItemName=” while len(@str)>0 Begin —– Found a subitem – set @location=charindex(@split,@str,1) if @location>0 Begin set @tempItem=substring(@str,1,@location-1) set @str=substring(@str,@location+1,len(@str)) End Else Begin set @[email protected] set @str=” end ———- Determine the name of the current sub item ————– set @location=charindex(@itemSplit,@tempItem,1) if @location>0 Begin set @tempItemName=substring(@tempItem,1,@location-1) if @[email protected] return substring(@tempItem,@location+1,len(@tempItem)) End End return ” End Go
declare @id varchar(30) select @id=dbo.Get_ArrayStrOfName(‘[email protected],[email protected],[email protected],[email protected]’, ‘,’, ‘@’, ‘ff’) print @id
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/110915.html Link to the original text :https://javaforall.cn
边栏推荐
- FIREBIRD使用经验总结
- Understand asp Net core - Authentication Based on jwtbearer
- Understand the rate control mode rate control mode CBR, VBR, CRF (x264, x265, VPX)
- 2021 Google vulnerability reward program review
- Talking about Net core how to use efcore to inject multiple instances of a context annotation type for connecting to the master-slave database
- Application of clock wheel in RPC
- Interface fonctionnelle, référence de méthode, Widget de tri de liste implémenté par lambda
- Research Report on market supply and demand and strategy of China's Sodium Tetraphenylborate (cas+143-66-8) industry
- Research Report on surgical otorhinolaryngology equipment industry - market status analysis and development prospect prediction
- Hair growth shampoo industry Research Report - market status analysis and development prospect forecast
猜你喜欢
Talking about Net core how to use efcore to inject multiple instances of a context annotation type for connecting to the master-slave database
Application of clock wheel in RPC
Anta is actually a technology company? These operations fool netizens
Principle and general steps of SQL injection
[hcie TAC] question 5 - 1
嵌入式软件架构设计-函数调用
Unity animation day05
Statistical learning: logistic regression and cross entropy loss (pytoch Implementation)
TypeError: list indices must be integers or slices, not str
QT graphical view frame: element movement
随机推荐
Stress, anxiety or depression? Correct diagnosis and retreatment
[native JS] optimized text rotation effect
Rearrange array
The four most common errors when using pytorch
System. Currenttimemillis() and system Nanotime (), which is faster? Don't use it wrong!
[North Asia data recovery] a database data recovery case where the partition where the database is located is unrecognized due to the RAID disk failure of HP DL380 server
实战:fabric 用户证书吊销操作流程
Scientific research cartoon | what else to do after connecting with the subjects?
基于check-point实现图数据构建任务
How to save the contents of div as an image- How to save the contents of a div as a image?
How can floating point numbers be compared with 0?
APOC自定义函数和过程
Understand the rate control mode rate control mode CBR, VBR, CRF (x264, x265, VPX)
C# 实现 FFT 正反变换 和 频域滤波
Oracle监听器Server端与Client端配置实例
ECCV 2022放榜了:1629篇论文中选,录用率不到20%
~88 running people practice
Using celery in projects
Talking about Net core how to use efcore to inject multiple instances of a context annotation type for connecting to the master-slave database
时序图数据建模与产业链分析