当前位置:网站首页>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
边栏推荐
- Accounting regulations and professional ethics [6]
- The new generation of domestic ORM framework sagacity sqltoy-5.1.25 release
- Review of Weibo hot search in 2021 and analysis of hot search in the beginning of the year
- error: ‘connect‘ was not declared in this scope connect(timer, SIGNAL(timeout()), this, SLOT(up
- Stress, anxiety or depression? Correct diagnosis and retreatment
- The 17 year growth route of Zhang Liang, an open source person, can only be adhered to if he loves it
- Web components series - detailed slides
- Detailed process of DC-2 range construction and penetration practice (DC range Series)
- [native JS] optimized text rotation effect
- Accounting regulations and professional ethics [7]
猜你喜欢
Anta is actually a technology company? These operations fool netizens
PR FAQ: how to set PR vertical screen sequence?
L1-072 scratch lottery
DC-2靶场搭建及渗透实战详细过程(DC靶场系列)
~88 running people practice
Model fusion -- stacking principle and Implementation
Overview of convolutional neural network structure optimization
Move, say goodbye to the past again
The new generation of domestic ORM framework sagacity sqltoy-5.1.25 release
Common knowledge of unity Editor Extension
随机推荐
Statistical learning: logistic regression and cross entropy loss (pytoch Implementation)
[North Asia data recovery] a database data recovery case where the disk on which the database is located is unrecognized due to the RAID disk failure of HP DL380 server
Communication mode based on stm32f1 single chip microcomputer
[Previous line repeated 995 more times]RecursionError: maximum recursion depth exceeded
Web components series - detailed slides
Market trend report, technical innovation and market forecast of tetrabromophthalate (pht4 diol) in China
After the eruption of Tonga volcano, we analyzed the global volcanic distribution and found that the area with the most volcanoes is here!
[hcie TAC] question 5 - 1
Accounting regulations and professional ethics [7]
L1-072 scratch lottery
Vscode prompt Please install clang or check configuration 'clang executable‘
What is torch NN?
Big God explains open source buff gain strategy live broadcast
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
Cut! 39 year old Ali P9, saved 150million
. Net applications consider x64 generation
MFC implementation of ACM basic questions encoded by the number of characters
Book of night sky 53 "stone soup" of Apache open source community
The 17 year growth route of Zhang Liang, an open source person, can only be adhered to if he loves it