当前位置:网站首页>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
边栏推荐
- 同构图与异构图CYPHER-TASK设计与TASK锁机制
- Hair growth shampoo industry Research Report - market status analysis and development prospect forecast
- China's roof ladder market trend report, technological innovation and market forecast
- Vscode setting outline shortcut keys to improve efficiency
- Variable cannot have type 'void'
- error: ‘connect‘ was not declared in this scope connect(timer, SIGNAL(timeout()), this, SLOT(up
- TypeError: list indices must be integers or slices, not str
- Book of night sky 53 "stone soup" of Apache open source community
- @EnableAspectAutoJAutoProxy_ Exposeproxy property
- Practice: fabric user certificate revocation operation process
猜你喜欢
函數式接口,方法引用,Lambda實現的List集合排序小工具
Redis' optimistic lock and pessimistic lock for solving transaction conflicts
Audio and video technology development weekly | 252
Model fusion -- stacking principle and Implementation
Model fusion -- stacking principle and Implementation
The new generation of domestic ORM framework sagacity sqltoy-5.1.25 release
Statistical learning: logistic regression and cross entropy loss (pytoch Implementation)
L1-072 scratch lottery
~88 running people practice
Stress, anxiety or depression? Correct diagnosis and retreatment
随机推荐
Feature extraction and detection 15-akaze local matching
Understand the rate control mode rate control mode CBR, VBR, CRF (x264, x265, VPX)
Move, say goodbye to the past again
How can floating point numbers be compared with 0?
Interpretation of the champion scheme of CVPR 2020 night target detection challenge
Salient map drawing based on OpenCV
After the eruption of Tonga volcano, we analyzed the global volcanic distribution and found that the area with the most volcanoes is here!
如何为ONgDB核心项目源码做贡献
Game theory
The new generation of domestic ORM framework sagacity sqltoy-5.1.25 release
Stress, anxiety or depression? Correct diagnosis and retreatment
Research Report on market supply and demand and strategy of China's well completion equipment industry
Practice: fabric user certificate revocation operation process
Recommend 10 excellent mongodb GUI tools
Principle and general steps of SQL injection
Rearrange array
Interface fonctionnelle, référence de méthode, Widget de tri de liste implémenté par lambda
DIY a low-cost multi-functional dot matrix clock!
Review of Weibo hot search in 2021 and analysis of hot search in the beginning of the year
[Chongqing Guangdong education] National Open University spring 2019 1396 pharmaceutical administration and regulations (version) reference questions