>  기사  >  데이터 베이스  >  sqlserver中去除字符串中连续的分隔符的sql语句

sqlserver中去除字符串中连续的分隔符的sql语句

WBOY
WBOY원래의
2016-06-07 18:05:411335검색

sqlserver中去除字符串中连续的分隔符的sql语句,需要的朋友可以参考下

以下测试用于去除任何字符串中连线的分隔符
代码如下:
--去除字符串中连续的分隔符
declare @str nvarchar(200)
declare @split nvarchar(200),@times int
set @str='中 国1 2 34 55 5 6 7 7';--字符
set @split=' '; --分隔符
select @times=(len(@str)-len(replace(@str,@split+@split,'')))/2
while @times>0
begin
set @str=REPLACE(@str,@split+@split,' ')
set @times=@times-1
end
select @str

希望对大家有作用

测试结果:

中 国1 2 34 55 5 6 7 7

(1 行受影响)
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.