在mysql中使用RollBack进行事务

时间:2015-08-13 08:09:45

标签: mysql stored-procedures phpmyadmin

通过创建此Strored Procedure我收到错误不知道如何修复它

这是我的sql

DROP PROCEDURE IF EXISTS Sp_Reservation;
DELIMITER $$
CREATE PROCEDURE Sp_Reservation
(
 IN name VARCHAR(150),
 IN email VARCHAR(100),
 IN mobile VARCHAR(15),
 IN cninc VARCHAR(15),
 IN cityID INT(10),
 IN checkin Date,
 IN checkout Date,
 IN noOfRooms INT(5),
 IN RoomID INT(10),
 IN RoomCategoryID INT(10),
 IN noOfChilds INT(5),
 IN noOfAdults INT(5),
 IN message VARCHAR(500),
 IN reservationStatus vARCHAR(10)
)
BEGIN
DECLARE CusID INT DEFAULT 1;

DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
ROLLBACK;
END;
START TRANSACTION;
BEGIN

SET CusID =( 
SELECT 
 IF(Max(customers.CustomerID) IS NULL,CUstID,customers.CustomerID) as
 CutomID FROM customers);

INSERT  INTO `customers` (customers.CustomerName,
                          customers.CustomerNID,
                          customers.CustomerEmail,
                          customers.CutomerMobile,
                          customers.CityID)
                VALUES(name,
                       cnic,
                       email,
                       Mobile,
                       CityID);

INSERT  INTO    `roomreservation`(roomreservation.CustomerID,
                                    roomreservation.RoomID,
                                  roomreservation.CheckIn,
                                  roomreservation.CheckOut,
                                  roomreservation.NoOfAdults,
                                  roomreservation.NoOfChildrens,
                                  roomreservation.Message,
                                  roomreservation.ReservationStatus)

SELECT  1,RoomID,checkin,checkout,noOfAdults,noOfChilds,message,reservationStatus
FROM rooms WHERE RoomID NOT IN
(
SELECT RoomID FROM roomreservation WHERE  ReservationStatus = 'Reserved'

AnD roomreservation.CheckIn BETWEEN checkIn AND   checkout
 ) ;
-- LIMIT (noOfRooms);

COMMIT;
END;
END$$
DELIMITER ;

ERROR:

SQL查询:

DELIMITER;

MySQL说:

  

1064 - 您的SQL语法出错;检查与MySQL服务器版本对应的手册,以便在第1行的“DELIMITER”附近使用正确的语法。

注意:我正在使用Phpmyadmin

1 个答案:

答案 0 :(得分:0)

好吧,除了您可以尝试将语句END$$更改为END $$之外,我没有看到您的过程代码有任何问题。如果仍然不起作用,那么您的Phpmyadmin客户端就会出现问题,并且对于DELIMITER $$语句不满意。尝试使用其他客户端(或)当前客户端的不同版本。