Home > Database > Mysql Tutorial > 解析逗号分隔信息的字符串为表格

解析逗号分隔信息的字符串为表格

WBOY
Release: 2016-06-07 14:56:59
Original
1242 people have browsed it

解析逗号分隔信息的字符串为表格 无 CREATE FUNCTION dbo.Parsecsvstr (@list VARCHAR(500))returns @tbl TABLE ( str VARCHAR(20))AS BEGIN DECLARE @valuelen INT, @pos INT, @nextpos INT SELECT @pos = 0, @nextpos = 1 WHILE @nextpos 0 BEGIN SELECT @n

解析逗号分隔信息的字符串为表格
CREATE FUNCTION dbo.Parsecsvstr (@list VARCHAR(500))
returns @tbl TABLE (
  str VARCHAR(20))
AS
  BEGIN
      DECLARE @valuelen INT,
              @pos      INT,
              @nextpos  INT

      SELECT @pos = 0,
             @nextpos = 1

      WHILE @nextpos > 0
        BEGIN
            SELECT @nextpos = Charindex(',', @list, @pos + 1)

            SELECT @valuelen = CASE
                                 WHEN @nextpos > 0 THEN @nextpos
                                 ELSE Len(@list) + 1
                               END - @pos - 1

            INSERT @tbl
                   (str)
            VALUES(Substring(@list, @pos + 1, @valuelen))

            SELECT @pos = @nextpos
        END

      RETURN
  END  
Copy after login
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template