MySQL存储过程出现事务语法错误
实际上,我已经从SQL Server移至MySQL,看来SQL语法完全不同,我很难完成创建以下存储过程的时间,因为我会遇到不同的错误。这是我第一次在Stackoverflow上发布,如果格式不友好,则表示歉意。提前致谢。
1-声明在此职位上无效,除了EOF,';'
2-设置在此位置无效,除了eof';'
3-提交在此职位上无效,除了eof';';'
DELIMITER //
CREATE PROCEDURE CreateCustomer(IN email VARCHAR(100),IN pass VARCHAR(128),IN phoneNumber VARCHAR(12),IN gender INT,IN birthday DATE)
BEGIN
DECLARE last_user_inserted INT DEFAULT 0;
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
ROLLBACK;
RESIGNAL;
END;
START TRANSACTION;
INSERT INTO users (emailAddress,passwordHash,phoneNumber) VALUES(email,pass,phoneNumber)
SET last_user_inserted = LAST_INSERT_ID();
INSERT INTO customers (user_id,gender,birthday) VALUES (last_user_id,gender, birthday)
COMMIT;
END;
DELIMITER ;
I have actually moved to MySQL from SQL Server and it looks like the SQL syntax is quite different, I'm having hard time to complete creating the below stored procedure as I'm get different kind of errors. this is my first time posting on Stackoverflow, apologies if the formatting is not friendly. Thanks in advance.
1- DECLARE is not valid at this position, Excepting EOF, ';'
2- SET is not valid at this position, Excepting EOF, ';'
3- COMMIT is not valid at this position, Excepting EOF, ';'
DELIMITER //
CREATE PROCEDURE CreateCustomer(IN email VARCHAR(100),IN pass VARCHAR(128),IN phoneNumber VARCHAR(12),IN gender INT,IN birthday DATE)
BEGIN
DECLARE last_user_inserted INT DEFAULT 0;
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
ROLLBACK;
RESIGNAL;
END;
START TRANSACTION;
INSERT INTO users (emailAddress,passwordHash,phoneNumber) VALUES(email,pass,phoneNumber)
SET last_user_inserted = LAST_INSERT_ID();
INSERT INTO customers (user_id,gender,birthday) VALUES (last_user_id,gender, birthday)
COMMIT;
END;
DELIMITER ;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
谢谢@P.Salmon,工作得很好。
Thanks @P.Salmon, worked just fine.