我的程序在运行时出错

时间:2017-03-30 08:01:42

标签: mysql

我的程序在运行时出错。我无法找到错误的地方?

CREATE PROCEDURE testing ()
  BEGIN
  DECLARE i INT;
  DECLARE vSite VARCHAR(100);
  set @i = 1;
  BEGIN WHILE @i <= 5 DO
      SET  @vSite = @vSite + CONCAT('LINE '+@i+', ');
     SET @i = @i + 1;
  END WHILE
        SELECT @vSite;
  END


/* Error 
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'SELECT @vSite; END' at line 10
*/

/* required output given below

LINE 1, LINE 2, LINE 3, LINE 4, LINE 5,

 */

enter image description here

1 个答案:

答案 0 :(得分:0)

由我自己解决

  delimiter //
CREATE procedure while_examples()
wholeblock:BEGIN
  declare str VARCHAR(255) default '';
  declare x INT default 0;
  SET x = 1;

  WHILE x <= 5 DO
    SET str = CONCAT(str,'LINE',x,',');
    SET x = x + 1;
  END WHILE;

  select str;
END//
CALL while_examples();

enter image description here