0

尝试创建 mysql 存储过程时出错。这是存储过程

    DELIMITER $$

CREATE

    PROCEDURE `crossqueue_bw`.`pr_SaveProfile`(IN vProfileId INT)

    BEGIN
        IF SELECT COUNT(ProfileId) FROM tblprofile WHERE ProfileId=vProfileId > 0 THEN

        ELSE

        END IF;
    END$$

DELIMITER ;

这是错误

    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 'select count(ProfileId) from tblprofile where ProfileId=vProfileId > 0 then

' at line 6

更新::

尝试使用此查询

    DELIMITER $$

CREATE

    PROCEDURE `crossqueue_bw`.`pr_SaveProfile`(IN vProfileId INT)

    BEGIN
        DECLARE v_count INT;
        v_count = SELECT COUNT(ProfileId) FROM tblprofile WHERE ProfileId=vProfileId;
        IF v_count > 0 THEN

        ELSE

        END IF;
    END$$

DELIMITER ;

这是错误

    Error Code : 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 '= SELECT COUNT(ProfileId) FROM tblprofile WHERE ProfileId=vProfileId;
        if v_cou' at line 7
4

2 回答 2

0

在您的 SP 中使用:

 DECLARE v_count int;

    set v_count := (SELECT COUNT(ProfileId) FROM tblprofile WHERE ProfileId=vProfileId);

    IF (v_count > 0) THEN
于 2012-12-04T16:32:44.217 回答
0

实际上,@Sashi 报告了 2 个错误,其中一个是缺少的括号,另一个是 if 和 else 部分中至少应该存在一个条件,否则它将显示错误。

这是工作代码

    DELIMITER $$

CREATE

    PROCEDURE `crossqueue_bw`.`pr_SavePrssosssfile`(IN vProfileId INT)

    BEGIN
        IF (SELECT COUNT(ProfileId) FROM tblprofile WHERE ProfileId=vProfileId) > 0 THEN
        SET @q=0;
        ELSE
        SET @q=0;
        END IF;
    END$$

DELIMITER ;
于 2012-12-05T10:44:17.897 回答