MySQL存储过程错误

时间:2014-03-03 18:39:42

标签: php mysql stored-procedures

我收到此错误

#1064 - 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 'lstart, lend; END IF; ELSE IF lstart = -1 THEN select count(*) a' at line 8"

在服务器上创建此存储过程但在我的localhost phpmyadmin中它是否正在创建而没有任何错误?

DELIMITER
create procedure getallmedia(IN cat int(2), IN asc_desc varchar(5), IN lstart int(11), IN lend int(11))
BEGIN
IF cat = -1 THEN
    IF asc_desc = 'asc' THEN
        IF lstart = -1 THEN
            select count(*) as result from bc_media where id <> -1;
        ELSE
            select * from bc_media where id <> -1 limit lstart, lend;
        END IF;
    ELSE
        IF lstart = -1 THEN
            select count(*) as result from bc_media where category = cat;
        ELSE
            select * from bc_media where category = cat order by id desc limit lstart, lend;
        END IF;
    END IF;
ELSE
    IF asc_desc = 'asc' THEN
        IF lstart = -1 THEN
            select count(*) as result from bc_media where category = cat;
        ELSE
            select * from bc_media where category = cat limit lstart, lend;
        END IF;
    ELSE
        IF lstart = -1 THEN
            select count(*) as result from bc_media where category = cat;
        ELSE
            select * from bc_media where category = cat order by id desc limit lstart, lend;
        END IF;
    END IF;
END IF;
END
DELIMITER ;

请帮帮我:(

1 个答案:

答案 0 :(得分:0)

我不确定,但是,在第一个DELIMITER 尝试放置$$

在最后 END 之后放上$$