CREATE PROCEDURE dowhile()
BEGIN
  DECLARE v1 INT DEFAULT 5;
  WHILE v1 > 0 DO
    SET v1 = v1 - 1;
  END WHILE;
END我运行mysql帮助里面的程序会报错,不知道为什么,请知道的告诉我一下错误代码: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INT DEFAULT 5' at line 3
(耗费 0 ms)错误代码: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHILE v1 > 0 DO
    SET v1 = v1 - 1' at line 1
(耗费 0 ms)错误代码: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'END WHILE' at line 1
(耗费 0 ms)错误代码: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'END' at line 1
(耗费 0 ms)

解决方案 »

  1.   

    没试你的语句没有任何错误啊。mysql> delimiter //
    mysql> CREATE PROCEDURE dowhile()
        -> BEGIN
        ->  DECLARE v1 INT DEFAULT 5;
        ->  WHILE v1 > 0 DO
        ->    SET v1 = v1 - 1;
        ->  END WHILE;
        -> END
        -> //
    Query OK, 0 rows affected (0.44 sec)mysql> delimiter ;
    mysql>
    mysql> call dowhile;
    Query OK, 0 rows affected (0.00 sec)mysql>
      

  2.   

    我运行确实报错,我在sqlyog里面运行的,mysql版本是5.0.22的
      

  3.   

    我执行
    mysql> delimiter ;
    mysql>
    mysql> call dowhile;
    没有反应
      

  4.   

    mysql> call dowhile();
    Query OK, 0 rows affected (0.00 sec)mysql> select version();
    +----------------------+
    | version()            |
    +----------------------+
    | 5.1.33-community-log |
    +----------------------+
    1 row in set (0.00 sec)mysql>
      

  5.   

    没问题
    估计是你的客户端对版本检查的语法问题
    你试下用mysql客户端直接运行看看
      

  6.   

    问题解决了,是客户端的原因,用dos下的可以,
    delimiter //
    CREATE PROCEDURE insertvalue(id int)
        BEGIN
        DECLARE v1 INT DEFAULT 0;
        WHILE v1 < 64 DO
        insert into world_value_data (worldid,value_idx) values (id,v1);
        SET v1 = v1 + 1;
        END WHILE;
        END
        //call insertvalue() //
    上面的代码可以