尝试创建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
答案 0 :(得分:0)
在您的SP使用中:
DECLARE v_count int;
set v_count := (SELECT COUNT(ProfileId) FROM tblprofile WHERE ProfileId=vProfileId);
IF (v_count > 0) THEN
答案 1 :(得分:0)
实际上dere是2个错误,一个是由@Sashi报告的缺失括号,另一个是至少一个条件应该在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 ;