无法识别的数据类型。 (在位置89处的“ @retArray”附近)

时间:2019-01-23 09:44:21

标签: mysql function

  

无法识别的数据类型。 (在“ @retArray”附近,位置89)

如何解决?或者我可以使用什么代替此功能? 还有其他解决方案吗?请建议我。

是否可以在mysql上返回表?

DELIMITER //

CREATE  FUNCTION Split
(
  p_sText varchar(8000), p_sDelim varchar(20) 
)
RETURNS @retArray TABLE (
  idx tinyint Primary Key, 
  value varchar(8000)
)
-- WITH ENCRYPTION
AS
BEGIN
  DECLARE v_idx int;
  DECLARE v_value varchar(8000);
  DECLARE v_bcontinue tinyint;
  DECLARE v_iStrike int;
  DECLARE v_iDelimlength int

  IF @sDelim = 'Space' THEN
    SET v_sDelim = ' ';
  END IF;

  SET v_idx = 1
  SET v_sText = LTrim(RTrim(@sText))
  SET v_iDelimlength = DATALENGTH(@sDelim)
  SET v_bcontinue = 1

  if(Char_length(rtrim(@sText)) = 0) then
    leave sp_lbl

    IF NOT ((v_iDelimlength = 0) or (@sDelim = 'Empty'));
  end if;
  BEGIN
    WHILE v_bcontinue = 1
    DO

      -- If you can find the delimiter in the text, retrieve the first element and
      -- insert it with its index into the return table.

      IF CHARINDEX(@sDelim, @sText)>0 THEN
        SET v_value = SUBSTRING(@sText,1, CHARINDEX(@sDelim,@sText)-1);
        BEGIN
          INSERT @retArray (idx, value)
          SELECT (v_idx, v_value)
        END;

        -- Trim the element and its delimiter from the front of the string.
        -- Increment the index and loop.
        SET v_iStrike = DATALENGTH(v_value) + v_iDelimlength;
        SET v_idx = v_idx + 1;
        SET v_sText = LTrim(Right(@sText,DATALENGTH(@sText) - v_iStrike));

      ELSE
        -- If you can't find the delimiter in the text, @sText is the last value in
        -- @retArray.
        SET v_value = @sText;
        BEGIN
          INSERT @retArray (idx, value)
          SELECT (v_idx, v_value)
        END;
        -- Exit the WHILE loop.
        SET v_bcontinue = 0;
      END IF;
    END WHILE
  END
  ELSE
    BEGIN
      WHILE v_bcontinue=1
      DO
        -- If the delimiter is an empty string, check for remaining text
        -- instead of a delimiter. Insert the first character into the
        -- retArray table. Trim the character from the front of the string.
        -- Increment the index and loop.
        IF DATALENGTH(@sText)>1 THEN
          SET v_value = SUBSTRING(@sText,1,1);
          BEGIN
            INSERT @retArray (idx, value)
            SELECT (v_idx, v_value)
          END;
          SET v_idx = v_idx+1;
          SET v_sText = SUBSTRING(@sText,2,DATALENGTH(@sText)-1);

      ELSE
        -- One character remains.
        -- Insert the character, and exit the WHILE loop.
        INSERT @retArray (idx, value)
        SELECT (v_idx, @sText)
        SET v_bcontinue = 0;
      END IF;
    END WHILE

  END

  RETURN
END

0 个答案:

没有答案