当前位置:网站首页>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
边栏推荐
- Application of clock wheel in RPC
- Object distance measurement of stereo vision
- Vscode setting outline shortcut keys to improve efficiency
- %F format character
- One question per day 540 A single element in an ordered array
- Expression #1 of ORDER BY clause is not in SELECT list, references column ‘d.dept_ no‘ which is not i
- Book of night sky 53 "stone soup" of Apache open source community
- Cut! 39 year old Ali P9, saved 150million
- AI system content recommendation issue 24
- A trap used by combinelatest and a debouncetime based solution
猜你喜欢

Common knowledge of unity Editor Extension

Cut! 39 year old Ali P9, saved 150million
![[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](/img/79/3fab19045e1ab2f5163033afaa4309.jpg)
[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

A trap used by combinelatest and a debouncetime based solution
![[hcie TAC] question 5 - 1](/img/e0/1b546de7628695ebed422ae57942e4.jpg)
[hcie TAC] question 5 - 1

Redis' optimistic lock and pessimistic lock for solving transaction conflicts

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

Stress, anxiety or depression? Correct diagnosis and retreatment

How to decrypt worksheet protection password in Excel file

~89 deformation translation
随机推荐
Proxifier global agent software, which provides cross platform port forwarding and agent functions
165 webmaster online toolbox website source code / hare online tool system v2.2.7 Chinese version
2021 Google vulnerability reward program review
~89 deformation translation
Unity prefab day04
What encryption algorithm is used for the master password of odoo database?
Function test - knowledge points and common interview questions
FIREBIRD使用经验总结
Redis: SDS source code analysis
How to save the contents of div as an image- How to save the contents of a div as a image?
[Chongqing Guangdong education] National Open University spring 2019 1396 pharmaceutical administration and regulations (version) reference questions
Feature extraction and detection 15-akaze local matching
Software Engineer vs Hardware Engineer
Research Report on market supply and demand and strategy of China's four sided flat bag industry
China's plastic processing machinery market trend report, technological innovation and market forecast
I let the database lock the table! Almost fired!
Hidden communication tunnel technology: intranet penetration tool NPS
基于check-point实现图数据构建任务
时序图数据建模与产业链分析
Principle and general steps of SQL injection