gpt4 book ai didi

mysql - Sql Query 中的错误 - 无法找到解决方案

转载 作者:行者123 更新时间:2023-11-29 00:36:01 25 4
gpt4 key购买 nike

我很难找到我的 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;

我收到此错误消息:

ERROR 1064 (42000): 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 'free seats”; ELSE SET status =”OK”; END IF;

RETURN status; END' at line 10

我会很感激一些帮助。

提前致谢

最佳答案

  • 不要更改 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 Query 中的错误 - 无法找到解决方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14288533/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com