再看一个实例
create function [dbo].[split]
(
@str as nvarchar(1000) ,
@delimiters as nvarchar(100)
)
returns @t table
(
pos int not null ,
value nvarchar(100) not null
)
as
begin
declare @end int ,
@start int ,
@pos int ,
@delino int ,
@strchar nvarchar(1) ,
@delimiter nvarchar(1)
select @str=replace(@str,' ',' '),@delimiters=replace(@delimiters,' ',' ')
set @str = ltrim(rtrim(@str))+substring(@delimiters, 1, 1)
select @pos = 1,@start = 1,@end = 1
while @end <= len(@str)
begin
select @strchar = substring(@str, @end, 1) ,
@delino = 1
while @delino <= len(@delimiters)
begin
set @delimiter = substring(@delimiters, @delino, 1)
if @strchar = @delimiter
begin
if substring(@str, @start, @end - @start) <> ''
begin
insert into @t
values ( @pos,substring(@str, @start,@end - @start) )
set @pos = @pos + 1
end
set @start = @end + 1
break
end
set @delino = @delino + 1
end
set @end = @end + 1
end
return
end
go
声明:本网页内容旨在传播知识,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。TEL:177 7030 7066 E-MAIL:11247931@qq.com