SQL Server數據庫中拆分字符串函數的具體方法
CREATE FUNCTION uf_StrSplit
(@origStr varchar(
@markStr varchar(
RETURNS @splittable table
(
str_id varchar(
string varchar(
)
AS
BEGIN
declare @strlen int
@TEMPstr varchar(
SELECT @strlen=LEN(@origStr)
@TEMPstr=
if(RIGHT(@origStr
begin
set @origStr = @origStr + @markStr
end
WHILE((@postion<=@strlen) and (@postion !=
BEGIN
IF(CHARINDEX(@markStr
BEGIN
SET @sublen=CHARINDEX(@markStr
END
ELSE
BEGIN
SET @sublen=@strlen
END
IF(@postion<=@strlen)
BEGIN
SET @TEMPid=@TEMPid+
SET @TEMPstr=SUBSTRING(@origStr
INSERT INTO @splittable(str_id
values(@TEMPid
IF(CHARINDEX(@markStr
BEGIN
SET @postion=CHARINDEX(@markStr
END
ELSE
BEGIN
SET @postion=@postion+
END
END
END
RETURN
END
例如
輸出結果
str_id string
From:http://tw.wingwit.com/Article/program/SQLServer/201311/22421.html