syntax error for mysql declaration of variable

前端 未结 2 1677
野的像风
野的像风 2020-12-29 04:26
CREATE PROCEDURE dorepeat(IN p1 INT)
BEGIN
  DECLARE x INT DEFAULT 0;
  REPEAT SET x = x + 1; UNTIL x > p1 END REPEAT;
END

I get an syntax error

相关标签:
2条回答
  • 2020-12-29 04:38

    Remove the DECLARE, you should be able to just do this:

    SET @x = 0;
    

    Also, variables need to be prefixed with the @ symbol

    0 讨论(0)
  • 2020-12-29 04:39

    You need to temporarily change the delimiter so the MySQL client doesn't think you're done with your statement when it sees the semicolon on line 3:

    DELIMITER //
    
    CREATE PROCEDURE dorepeat(IN p1 INT)
    BEGIN
      DECLARE x INT DEFAULT 0;
      REPEAT SET x = x + 1; UNTIL x > p1 END REPEAT;
    END//
    
    DELIMITER ;
    
    0 讨论(0)
提交回复
热议问题