SQL按分隔字符串把字符串分解成列表方式
SQL按分隔字符串把字符串分解成列表形式declare @str varchar(max)declare @splitChar varchar(max)decl
SQL按分隔字符串把字符串分解成列表形式
declare @str varchar(max);
declare @splitChar varchar(max);
declare @table table(litchar varchar(max))
declare @i int
declare @splitCharLen int
set @str='s/e/r/r/t/f/vxc/vx/cvx/cvx/cvxc/vx/' --要分解的字符串
set @splitChar='/' --分隔符
set @splitCharLen=LEN(@splitChar);
set @i=charindex(@splitChar,@str)
if @i>0
begin
while @i>0
begin
insert into @table (litchar)values(left(@str,@i-1))
set @str=substring(@str,@i+@splitCharLen,len(@str)-@i)
set @i=charindex(@splitChar,@str)
end
insert into @table (litchar)values(@str)
end
else
insert into @table (litchar)values(@str)
delete from @table where litchar='' or litchar is null
select * from @table ;