当前位置:网站首页>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
边栏推荐
- Market trend report, technical innovation and market forecast of electrochromic glass and devices in China and Indonesia
- What is the catalog of SAP commerce cloud
- The vscode waveform curve prompts that the header file cannot be found (an error is reported if the header file exists)
- FIREBIRD使用经验总结
- Understand asp Net core - Authentication Based on jwtbearer
- Redis: SDS source code analysis
- ~89 deformation translation
- Cut! 39 year old Ali P9, saved 150million
- Communication mode based on stm32f1 single chip microcomputer
- Hair and fuzz interceptor Industry Research Report - market status analysis and development prospect forecast
猜你喜欢
![[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

AutoCAD - set color

Principle and general steps of SQL injection

~89 deformation translation

Filtered off site request to

D3D11_ Chili_ Tutorial (2): draw a triangle

Talking about Net core how to use efcore to inject multiple instances of a context annotation type for connecting to the master-slave database

Function test - knowledge points and common interview questions

Detailed process of DC-2 range construction and penetration practice (DC range Series)

Working group and domain analysis of Intranet
随机推荐
Audio and video technology development weekly | 252
时钟轮在 RPC 中的应用
~89 deformation translation
Filtered off site request to
基于check-point机制的任务状态回滚和数据分块任务
How to decrypt worksheet protection password in Excel file
Qt---error: ‘QObject‘ is an ambiguous base of ‘MyView‘
Market trend report, technical innovation and market forecast of taillight components in China
Application of clock wheel in RPC
Selenium element interaction
[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
Market trend report, technical innovation and market forecast of China's hair repair therapeutic apparatus
Review of Weibo hot search in 2021 and analysis of hot search in the beginning of the year
Lv166 turned over
Accounting regulations and professional ethics [11]
[Previous line repeated 995 more times]RecursionError: maximum recursion depth exceeded
. Net delay queue
Research Report on market supply and demand and strategy of surgical stapler industry in China
Summary of database 2
Move, say goodbye to the past again