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 @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 ;
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 ;
本文将介绍如何使用SQL查询语言实现字符串分解功能,并通过实例展示如何应用此功能进行复杂数据处理。包括设置变量存储字符串、分隔符,以及通过循环和函数实现字符串分割和插入操作,最后删除空值并展示分割后的结果。
1万+

被折叠的 条评论
为什么被折叠?



