在我的sql查询中发现错误有很大的困难。
CREATE FUNCTION freeSeats(bookingID INT)
RETURNS VARCHAR(30)
BEGIN
DECLARE numberBooked INT ;
DECLARE status VARCHAR(30);
SELECT count(*) FROM passenger WHERE Booking IN(SELECT Id FROM booking WHERE
Flight = (SELECT Flight FROM booking WHERE Id = bookingID)) INTO numberBooked;
IF (numberBooked > 59) THEN SET status =”No free seats”;
ELSE SET status =”OK”;
END IF;
RETURN status;
END;
我收到此错误消息:
错误1064(42000):SQL语法中有错误;请检查
与右边MySQL服务器版本相对应的手册
“free seats”附近使用的语法;ELSE SET status=“OK”;END IF;
返回状态;结束于第10行
我很感激你的帮助。
提前谢谢
最佳答案
不要让get更改DELIMITER
使用单引号
例子,
DELIMITER $$
CREATE FUNCTION freeSeats(bookingID INT)
RETURNS VARCHAR(30)
BEGIN
DECLARE numberBooked INT ;
DECLARE status VARCHAR(30);
SET numberBooked =
(
SELECT count(*)
FROM passenger
WHERE Booking IN
( SELECT Id
FROM booking
WHERE Flight = (SELECT Flight FROM booking WHERE Id = bookingID)
)
);
IF (numberBooked > 59) THEN
SET status = 'No free seats';
ELSE
SET status = 'OK';
END IF;
RETURN status;
END $$
DELIMITER ;
关于mysql - SQL查询中的错误-找不到解决方案,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14288533/