当前位置:网站首页>[SQL] string series 2: split a string into multiple lines according to specific characters

[SQL] string series 2: split a string into multiple lines according to specific characters

2022-04-23 20:37:00 Wood is easy to follow the wind

Break a string into multiple lines according to specific characters , for example : Will Mathematics , Physics , history , biological , Chinese language and literature , English , chemical , Geographical division 8 Row display .

      
      
Select * From dbo.StrToColEx(' mathematics , Physics , history , biological , Chinese language and literature , English , chemical , Geography ',',') b
  • 1.

【SQL】 String series 2: Break a string into multiple lines according to specific characters _ character string

      
      
CREATE function dbo.StrToColEx (@str Varchar(max),@separator varchar(10))
returns @T table(Col varchar(max),sort int)
as
Begin

Declare @i int
declare @index int
set @index=1
Set @i=0
Set @[email protected][email protected]
While(@i<=len(@str))
Begin
Insert @T select substring(@str,@i,charindex(@separator,@str COLLATE Chinese_PRC_CS_AS_KS_WS,@i)[email protected]) ,@index
Select @i=charindex(@separator,@str COLLATE Chinese_PRC_CS_AS_KS_WS,@i)+LEN(@separator)
set @[email protected]+1
End
return
End
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.


版权声明
本文为[Wood is easy to follow the wind]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231922596556.html