复制代码 代码如下:
CREATE FUNCTION dbo.f_splitstr(
@str varchar(8000)
)RETURNS @r TABLE(id int IDENTITY(1, 1), value varchar(5000))
AS
BEGIN
/* Function body */
DECLARE @pos int
SET @pos = CHARINDEX(‘,’, @str)
WHILE @pos > 0
BEGIN
INSERT @r(value) VALUES(LEFT(@str, @pos – 1))
SELECT
@str = STUFF(@str, 1, @pos, ”),
@pos = CHARINDEX(‘,’, @str)
END
IF @str > ”
INSERT @r(value) VALUES(@str)
RETURN
END
select * from f_splitstr(‘中,国,人’)
原创文章,作者:254126420,如若转载,请注明出处:https://blog.ytso.com/234031.html