创建存储过程时出现MySQL错误#1064

时间:2014-12-21 11:55:16

标签: mysql stored-procedures

以下是代码:

IF(selected_item_id IS NOT NULL AND selected_category IS NOT NULL) THEN

    IF(selected_item_id <> "all") THEN

        SELECT i.id, i.name, i.summary, i.description, i.location, c.name AS 'category_name' FROM items i, categories c WHERE i.category_id = c.id AND i.id LIKE selected_item_id;

    ELSE IF(selected_item_id = "all" AND selected_category <> "all" AND selected_category in (SELECT name FROM categories)) THEN

        SELECT i.id, i.name, i.summary, i.description, i.location, c.name AS 'category_name' FROM items i, categories c WHERE i.category_id = c.id AND c.name LIKE selected_category;

    ELSE IF(selected_item_id = "all" AND selected_category = "all") THEN

        SELECT i.id, i.name, i.summary, i.description, i.location, c.name AS 'category_name' FROM items i, categories c WHERE i.category_id = c.id;

    END IF

END IF

当我尝试保存它时,我得到:

MySQL说:#1064在第17行'END IF'附近(这是最后一个END IF)

非常感谢帮助。

1 个答案:

答案 0 :(得分:1)

您不需要在ELSE和IF之间添加空格。有关详细信息,请参阅this。最后用分号结束你。