CREATE FUNCTION [dbo].[up_splitSTR]( @s VARCHAR(8000), --待分拆的字符串 @split VARCHAR(10) --数据分隔符 )RETURNS @re TABLE(col VARCHAR(100)) AS BEGIN DECLARE @splitlen INT SET @splitlen=LEN(@split+'a')-2 WHILE CHARINDEX(@split,@s)>0 BEGIN INSERT @re VALUES(LEFT(@s,CHARINDEX(@split,@s)-1)) SET @s=STUFF(@s,1,CHARINDEX(@split,@s)+@splitlen,'') END INSERT @re VALUES(@s) RETURN END
用法:
SELECT * FROM dbo.up_splitSTR('root.Mnue01.0101.010102','.')
结果: