当前位置:Gxlcms > 数据库问题 > MSSQL字符串取相应的第几个数组值

MSSQL字符串取相应的第几个数组值

时间:2021-07-01 10:21:17 帮助过:71人阅读

create function Get_StrArrayStrOfIndex
(
@str varchar(5000), --要分割的字符串
@split varchar(10), --分隔符号
@index int --取第几个元素
)
returns varchar(5000)
as
begin
declare @location int
declare @start int
declare @next int
declare @seed int

set @str=ltrim(rtrim(@str))
set @start=1
set @next=1
set @seed=len(@split)

set @location=charindex(@split,@str)
while @location<>0 and @index>@next
begin
set @start=@location+@seed
set @location=charindex(@split,@str,@start)
set @next=@next+1
end
if @location =0 select @location =len(@str)+1
return substring(@str,@start,@location-@start)
end

 

GO

 

print dbo.Get_StrArrayStrOfIndex(‘我是,中国人‘,‘,‘,0)

 

https://blog.csdn.net/NextStand/article/details/50999738

MSSQL字符串取相应的第几个数组值

标签:rtrim(   and   oca   creat   detail   star   int   个数   sql   

人气教程排行