当前位置:网站首页>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
边栏推荐
- C implementation defines a set of intermediate SQL statements that can be executed across libraries
- 多年锤炼,迈向Kata 3.0 !走进开箱即用的安全容器体验之旅| 龙蜥技术
- Talking about Net core how to use efcore to inject multiple instances of a context annotation type for connecting to the master-slave database
- 对人胜率84%,DeepMind AI首次在西洋陆军棋中达到人类专家水平
- D3D11_ Chili_ Tutorial (2): draw a triangle
- The vscode waveform curve prompts that the header file cannot be found (an error is reported if the header file exists)
- Cut! 39 year old Ali P9, saved 150million
- Variable cannot have type 'void'
- Accounting regulations and professional ethics [7]
- How can floating point numbers be compared with 0?
猜你喜欢

Big God explains open source buff gain strategy live broadcast

Interface test - knowledge points and common interview questions
![[North Asia data recovery] data recovery case of database data loss caused by HP DL380 server RAID disk failure](/img/f0/12dd17e840a23dc9ded379e1fd7454.jpg)
[North Asia data recovery] data recovery case of database data loss caused by HP DL380 server RAID disk failure

A trap used by combinelatest and a debouncetime based solution

对人胜率84%,DeepMind AI首次在西洋陆军棋中达到人类专家水平

MySQL learning notes - data type (2)

error: ‘connect‘ was not declared in this scope connect(timer, SIGNAL(timeout()), this, SLOT(up

Actual combat | use composite material 3 in application

The new generation of domestic ORM framework sagacity sqltoy-5.1.25 release

Vscode setting outline shortcut keys to improve efficiency
随机推荐
~88 running people practice
[flask] ORM one to many relationship
时钟轮在 RPC 中的应用
基于check-point机制的任务状态回滚和数据分块任务
CMPSC311 Linear Device
How can floating point numbers be compared with 0?
Detailed process of DC-2 range construction and penetration practice (DC range Series)
[hcie TAC] question 5 - 1
[tutorial] yolov5_ DeepSort_ The whole process of pytoch target tracking and detection
Research Report on plastic recycling machine industry - market status analysis and development prospect forecast
The 17 year growth route of Zhang Liang, an open source person, can only be adhered to if he loves it
How to save the contents of div as an image- How to save the contents of a div as a image?
C language: implementation of daffodil number function
I let the database lock the table! Almost fired!
AutoCAD - set color
Software Engineer vs Hardware Engineer
@EnableAspectAutoJAutoProxy_ Exposeproxy property
System.currentTimeMillis() 和 System.nanoTime() 哪个更快?别用错了!
Unity animation day05
C implementation defines a set of intermediate SQL statements that can be executed across libraries