-3

我需要有人帮我找出我的 sql 查询中的错误:

CREATE PROCEDURE confirm(IN bookingID INT, OUT status VARCHAR(40))
BEGIN
DECLARE numberOfPass INT;
DECLARE contactStatus VARCHAR(30);
SET numberOfPass = (SELECT count(*) FROM passenger WHERE passenger.Booking = bookingID);
SET contactStatus = (SELECT contact FROM booking WHERE booking.Id = bookingID);
IF numberOfPass <> (SELECT numberOfSeats FROM booking WHERE booking.Id  = bookingID)) THEN SET status = "Passenger information missing";
ELSE IF ISNULL(contactStatus) THEN SET status ="Contact missing for booking";
ELSE SET status = "OK";
END IF;
END; 

我收到以下错误消息:

ERROR 1064 (42000):您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在 ') THEN SET status = "Passenger information missing" 附近使用正确的语法;ELSE IF ISNULL(contactStatu' 在第 7 行

可能是什么错误?

提前致谢。

4

3 回答 3

4

你有一个额外的括号

IF numberOfPass <> (SELECT numberOfSeats FROM booking WHERE booking.Id  = bookingID))
于 2013-01-11T16:39:48.923 回答
2
  • 利用ELSEIF
  • 去掉多余的括号

完整的查询,

DELIMITER $$
CREATE PROCEDURE confirm(IN bookingID INT, OUT status VARCHAR(40))
BEGIN
    DECLARE numberOfPass INT;
    DECLARE contactStatus VARCHAR(30);
    SET numberOfPass = (SELECT count(*) FROM passenger WHERE passenger.Booking = bookingID);
    SET contactStatus = (SELECT contact FROM booking WHERE booking.Id = bookingID);
    IF numberOfPass <> (SELECT numberOfSeats FROM booking WHERE booking.Id  = bookingID) THEN 
        SET status = "Passenger information missing";
    ELSEIF ISNULL(contactStatus) THEN 
        SET status ="Contact missing for booking";
    ELSE 
        SET status = "OK";
    END IF;
END $$
DELIMITER ;
于 2013-01-11T16:40:09.493 回答
1

额外的)在你的代码中......

                                                                                    !!!
 IF numberOfPass <> (SELECT numberOfSeats FROM booking WHERE booking.Id  = bookingID))
于 2013-01-11T16:43:13.530 回答