我非常習慣在TSQL中編寫代碼,MySQL正在進行一些調整,但我認爲我已經掌握了大部分內容。我有一個存儲過程,但不會讓步,我已經閱讀並重讀了100次,閱讀了所有我能找到的錯誤,但仍然沒有運氣。Missing END - Mysql存儲過程
在11號線及本聲明的末尾:
CREATE TEMPORARY TABLE ReturnAvalRooms (roomID int);
我得到的錯誤「缺少結束」,儘管這是在我的查詢的開始。 我已經檢查並重新檢查了所有內容都被聲明並設置爲合適的;但只是無法弄清楚爲什麼我得到這個錯誤。
下面是存儲過程的完整副本。
CREATE PROCEDURE `Get_AvailRooms` (IN StartDate datetime, IN EndDate datetime, IN RoomType int)
BEGIN
DECLARE PStartDate datetime;
DECLARE PEndDate datetime;
DECLARE PRoomType int;
SET PStartDate = StartDate;
SET PEndDate = EndDate;
SET PRoomType = RoomType;
CREATE TEMPORARY TABLE AvaliableNowRooms AS (SELECT idRooms FROM rooms WHERE RoomNextAvail < PStartDate AND RoomTypeID = PRoomType);
CREATE TEMPORARY TABLE ReturnAvalRooms (roomID int);
DECLARE AvailRooms CURSOR FOR SELECT * FROM AvaliableNowRooms;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
DECLARE RoomID INT;
OPEN AvailRooms;
read_loop: LOOP
FETCH AvailRooms INTO RoomID;
IF done THEN
LEAVE read_loop;
END IF;
DECLARE Bookings CURSOR FOR SELECT BookingStartDate, BookingEndDate, BookingRoomID FROM Booking WHERE BookingRoomID = RoomID AND BookingEndDate < PStartDate;
DECLARE PBookingStartDate datetime;
DECLARE PBookingEndDate datetime;
DECLARE PBookingRoomID,
OPEN Bookings
Booking_Read: LOOP
FETCH Bookings INTO PBookingStartDate, PBookingEndDate, PBookingRoomID;
IF done THEN
LEAVE Booking_Read;
END IF;
IF PBookingStartDate BETWEEN PStartDate AND PEndDate
LEAVE Booking_Read;
ELSE IF PBookingEndDate BETWEEN PStartDate AND PEndDate
LEAVE Booking_Read;
ELSE
INSERT INTO ReturnAvalRooms (id) values (PBookingRoomid);
END LOOP;
CLOSE Bookings;
END
END LOOP;
CLOSE AvailRooms;
END
SELECT * FROM ReturnAvalRooms
END
+10對於風格 - 給了這個查詢幾個現在進行了一些改動,以解釋新創建的房間有一個無效的日期,到目前爲止我不能錯。最初的理論,如果你想知道的是第一個臨時表將捕獲所有可用的房間,無論未來的預訂。一旦發生這種情況,它可以通過帶有roomID的預訂表循環,並收集所有未來的預訂,檢查交叉日期,然後將其添加到臨時表(如果沒有)。你的更好。謝謝!測試繼續... – Caz1224