[英]Transaction with RollBack in mysql
By Creating this Strored
Procedure
i am getting error dont know how to fix it 通过创建此
Strored
Procedure
我遇到错误,不知道如何解决
Here is my sql 这是我的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 query: SQL查询:
DELIMITER ; 定界符;
MySQL said: MySQL说:
1064 - You have an error in your SQL syntax;
1064-您的SQL语法有误; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DELIMITER' at line 1.
查看与您的MySQL服务器版本相对应的手册,以找到在第1行的'DELIMITER'附近使用正确的语法。
Note: I am using Phpmyadmin 注意:我正在使用Phpmyadmin
Well, I don't see any issue with your procedure code except that you can try changing the statement END$$
to END $$
. 好吧,我看不到您的过程代码有任何问题,只是您可以尝试将语句
END$$
更改为END $$
。 If still doesn't work then there is problem with your Phpmyadmin
client and somehow it's not happy with the statement DELIMITER $$
. 如果仍然无法正常运行,则说明您的
Phpmyadmin
客户端存在问题,并且对DELIMITER $$
语句不满意。 Try using a different client (or) a different version of current client. 尝试使用其他客户端(或)当前客户端的其他版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.