MySQL 具有事务语法错误的存储过程
MySQL stored procedure with transaction syntax error
我实际上已经从 SQL 服务器移动到 MySQL,看起来 SQL 语法完全不同,我很难完成以下存储过程的创建因为我遇到了不同类型的错误。这是我第一次在 Whosebug 上发帖,如果格式不友好,我们深表歉意。提前致谢。
1- DECLARE 在此位置无效,EOF 除外,';'
2- SET 在此位置无效,EOF 除外,';'
3- COMMIT 在此位置无效,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 ;
谢谢@P.Salmon,工作得很好。
DELIMITER //
CREATE PROCEDURE CreateCustomer(IN email VARCHAR(100),IN passVARCHAR(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 customer (user_id,gender,birthday) VALUES (last_user_id,gender, birthday);
COMMIT;
END//
DELIMITER ;
我实际上已经从 SQL 服务器移动到 MySQL,看起来 SQL 语法完全不同,我很难完成以下存储过程的创建因为我遇到了不同类型的错误。这是我第一次在 Whosebug 上发帖,如果格式不友好,我们深表歉意。提前致谢。
1- DECLARE 在此位置无效,EOF 除外,';'
2- SET 在此位置无效,EOF 除外,';'
3- COMMIT 在此位置无效,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 ;
谢谢@P.Salmon,工作得很好。
DELIMITER //
CREATE PROCEDURE CreateCustomer(IN email VARCHAR(100),IN passVARCHAR(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 customer (user_id,gender,birthday) VALUES (last_user_id,gender, birthday);
COMMIT;
END//
DELIMITER ;