无法在mysql中创建存储过程

时间:2018-02-04 07:11:20

标签: mysql sql stored-procedures sequelpro

我创建了一个存储过程如下:

create procedure load_data()
BEGIN
DECLARE vcounter INT DEFAULT 0;
while vcounter < 1000 do
    if vcounter % 2<>0 then 
        INSERT INTO EMPDetails ( id, name ) VALUES ( null, 'Adrian','Test','1989-07-09',vcounter);
    else 
        INSERT INTO EMPDetails ( id, name ) VALUES ( null, 'Jimmy','Bank','1989-07-06',vcounter);
    set vcounter=vcounter+1;
end while;
END 

我在续集专业版中执行了它,但它总是说这个

[ERROR in query 1] 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 '' at line 3
Execution stopped! 

我检查了我的程序,看起来很顺序。我做错了什么?

1 个答案:

答案 0 :(得分:1)

您需要使用END IF结束 if-else

if vcounter % 2<>0 then 
        INSERT INTO EMPDetails ( id, name ) VALUES ( null, 'Adrian','Test','1989-07-09',vcounter);
    else 
        INSERT INTO EMPDetails ( id, name ) VALUES ( null, 'Jimmy','Bank','1989-07-06',vcounter);
    set vcounter=vcounter+1;
end if;

此外,INSERT 必须 中的列列表与指定的值匹配。