Chinaunix首页 | 论坛 | 博客
  • 博客访问: 266994
  • 博文数量: 42
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 534
  • 用 户 组: 普通用户
  • 注册时间: 2012-02-26 19:11
文章分类
文章存档

2014年(42)

我的朋友

分类: Mysql/postgreSQL

2014-06-07 14:06:44


DROP PROCEDURE IF EXISTS test.t1 $$
DELIMITER $$
CREATE PROCEDURE t1()
    BEGIN
SET autocommit=0;
      DECLARE cnt INT DEFAULT 0;     -- it is wrong order
       WHILE cnt <= 10000 DO
        INSERT INTO t1 VALUES (cnt);
        SET cnt = cnt +1;
       END WHILE;
       COMMIT;
    END$$
DELIMITER ;

and when run the sql block; there was error info , follow this:
Error Code: 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 'DECLARE cnt INT DEFAULT 0;     
       WHILE cnt <= 10000 DO
        INSERT INTO' at line 4

[solved way]:  declare must be set before autocommit;

DELIMITER $$
DROP PROCEDURE IF EXISTS test.t1 $$
DELIMITER $$
CREATE PROCEDURE t1()
BEGIN
DECLARE cnt INT DEFAULT 0; -- it is right order
SET autocommit=0;
WHILE cnt <= 10000 DO
INSERT INTO t1 VALUES (cnt);
SET cnt = cnt +1;
END WHILE;
COMMIT;
END$$
DELIMITER ;

Execution Time : 0.005 sec
Transfer Time  : 0.097 sec
Total Time     : 0.102 sec

阅读(1681) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~