-1

我正在从 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 附近的语法错误。

4

2 回答 2

0

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

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

于 2010-04-14T16:16:44.843 回答
-1

想通了...正确的语法是:

ELSEIF

代替

ELSE IF
于 2010-04-14T16:59:59.233 回答