MySql Workbench和IF语句的语法错误

时间:2010-04-14 16:07:19

标签: mysql mysql-workbench

我正在从T-SQL迁移到MySql语法,并且不知道如何克服Workbench 5.1.18给出的语法错误:

-- --------------------------------------------------------------------------------
-- Routine DDL
-- --------------------------------------------------------------------------------
DELIMITER //

CREATE PROCEDURE `SysTicket`.`GetProductionLines` (aId INT, aActive INT, aResponsible VARCHAR(8000))
BEGIN
    IF(aId > 0) THEN SELECT * FROM ProductionLine WHERE Id = @Id;

    ELSE IF( aActive <> -1 AND aResponsible = '|$EMPTYARG$|') THEN SELECT * FROM ProductionLine;

    ELSE IF(aResponsible = '|$EMPTYARG&|') THEN SELECT * FROM ProductionLine WHERE Active = aActive;

    ELSE SELECT * FROM ProductionLine WHERE Active = aActive AND Responsible LIKE CONCAT('%', aResponsible, '%');

    END IF;    
END//

它说END附近的语法错误(最后一行) ty提前。

2 个答案:

答案 0 :(得分:0)

从IF语句中删除括号以进行单个比较,或添加逗号而不是AND。

http://dev.mysql.com/doc/refman/5.1/en/control-flow-functions.html#function_if

答案 1 :(得分:-1)

想出来...... 正确的语法是:

ELSEIF

而不是

ELSE IF