简体   繁体   中英

MySQL error #1064 while creating stored procedure

Here is the code:

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

When I try to save it, I get :

MySQL Said: #1064 near 'END IF' at line 17 (that's the last END IF)

Help is much appreciated.

You dont need to add space in between ELSE and IF. See this for details. And end you END IF with semicolon.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM