日期:2014-05-16  浏览次数:20805 次

麻烦大家看看这个Mysql 的存储过程错在哪?
create procedure p1()
  BEGIN
  DECLARE v INT;
SET @uuid1 = UUID();
  SET v=0;
  WHILE v<2 DO
  INSERT INTO t1(id1,@uuid1);
  SET v= v+1;
  END WHILE;
  END;
   
而t1表结构是
create table t1(
  id1 int(10) not null primary key AUTO_INCREMENT,
  t1c1 varchar(100))AUTO_INCREMENT = 1;

ERROR 1064 (42000): You have an error in your SQL syntax;

------解决方案--------------------
SQL code
mysql> delimiter //
mysql>
mysql> create procedure p1()
    -> BEGIN
    -> DECLARE v INT;
    -> SET @uuid1 = UUID();
    -> SET v=0;
    -> WHILE v<2 DO
    ->  INSERT INTO t1 values (id1,@uuid1); -- ACMAIN values !
    -> SET v= v+1;
    -> END WHILE;
    -> END;
    -> //
Query OK, 0 rows affected (0.00 sec)

mysql> delimiter ;
mysql>

------解决方案--------------------
DELIMITER $$
DROP PROCEDURE IF EXISTS ddt$$
CREATE PROCEDURE `testa`.`ddt`()
BEGIN
DECLARE v INTEGER;
SET @uuid1=UUID();
SET v=0;
WHILE v<2 DO
INSERT INTO t1 VALUES(id1,@uuid1);
SET v= v+1;
END WHILE;
END$$

DELIMITER ;
------解决方案--------------------
SET @uuid1 = UUID(); @uuid2 = UUID();@uuid3 = UUID(); @uuid4 = UUID();@uuid5 = UUID(); @uuid6 = UUID();@uuid7 = UUID(); @uuid8 = UUID();@uuid9 = UUID(); @uuid10 = UUID();@uuid11 = UUID();@uuid12 = UUID();@uuid13 = UUID();@uuid14 = UUID();@uuid15 = UUID();@uuid16 = UUID();@uuid17= UUID();@uuid18 = UUID();@uuid19 = UUID();@uuid20 = UUID();

分号改成逗号!

mysql> set @x=1,@y=2;
Query OK, 0 rows affected (0.00 sec)