我正在运行一个存储过程,该过程现在生成错误。以前,当我开发此存储过程时,它运行良好。但是现在它会产生这样的错误:
BIGINT UNSIGNED value is out of range in '(`epermit_db_old`.`rtm`.`NoOfRooms` - (select count(`epermit_db_old`.`br`.`BookingId`) from `epermit_db_old`.`bookedroom` `br` where ((`epermit_db_old`.`br`.`RoomTypeId` = (varInRoomTypeId@1)) and (`epermit_db_old`.`br`.`GuestHouseId` = (varInGuestHouseId@0)) and (`epermit_db_old`.`br`.`StayDate` = (varInStayDate@2)) and ((`epermit_db_old`.`br`.`Status` = 'Booked') or (hour(timediff((now()),`epermit_db_old`.`br`.`SessionStart`)) < 1)))))
我将过程称为
CALL spCheckRoomAvailbility('105','3','2018-10-28','2018-10-30','1')
我还将在下面附加存储过程
CREATE DEFINER=`root`@`localhost` PROCEDURE `spCheckRoomAvailbility`(
IN `varInGuestHouseId` INT,
IN `varInRoomTypeId` INT,
IN `varInStayDate` DATETIME,
IN `varCheckOut` DATETIME
,
IN `NoOfRooms` INT
)
LANGUAGE SQL
NOT DETERMINISTIC
CONTAINS SQL
SQL SECURITY DEFINER
COMMENT ''
BEGIN
DECLARE varStatus CHAR(5) DEFAULT 'Y';
DECLARE varResult BIGINT;
WHILE(varInStayDate < varCheckOut)DO
SELECT t.AvailRooms into varResult from (SELECT (RTM.NoOfRooms) -
(SELECT COUNT(BookingId) FROM BookedRoom BR WHERE BR.StayDate = varInStayDate AND BR.GuestHouseId = varInGuestHouseId AND BR.RoomTypeId = varInRoomTypeId AND (BR.Status = 'Booked' OR HOUR(TIMEDIFF(NOW(),BR.SessionStart)) < 1))
AS AvailRooms FROM RoomTypeMaster RTM WHERE RTM.GuestHouseId = varInGuestHouseId AND RTM.RoomTypeId = varInRoomTypeId) t;
if varResult < NoOfRooms then
set varStatus = 'N';
end if;
select DATE_ADD(varInStayDate,INTERVAL 1 DAY) into varInStayDate;
END WHILE;
SELECT rs.avail,ghd.GuestHouseName as GuestHouseName,ghd.Address as Address, ghd.RoomType, ghd.RoomRent from (SELECT GHM.GuestHouseName AS GuestHouseName, GHM.Address AS Address, RTM.RoomType AS RoomType, RTM.RoomRent AS RoomRent FROM GuesthouseMaster GHM, RoomTypeMaster RTM WHERE GHM.GuestHouseId = varInGuestHouseId AND RTM.RoomTypeId = varInRoomTypeId AND RTM.GuestHouseId = varInGuestHouseId) as ghd,(select varStatus as avail) as rs;
END