当我遇到下面执行查询的错误时,我正在使用MySQL。
CREATE PROCEDURE insert_apply(
IN in_username VARCHAR(25),
IN in_machine_id INT
)
BEGIN
START TRANSACTION;
IF EXISTS (SELECT * FROM machine WHERE machine.id = in_machine_id AND machine.available = 1) THEN
INSERT INTO user_machine VALUES (in_username, in_machine_id);
UPDATE machine SET machine.available = 0 WHERE machine.id = in_machine_id;
END IF;
COMMIT;
END;
MySQL错误是,
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 6
"靠近'' "意思?如何更正此错误?
非常感谢。
答案 0 :(得分:0)
我认为这些对你有用。实际上你错过了DELIMITER //
DELIMITER //
CREATE PROCEDURE insert_apply(
IN in_username VARCHAR(25),
IN in_machine_id INT
)
BEGIN
START TRANSACTION;
IF EXISTS (SELECT * FROM machine WHERE machine.id = in_machine_id AND machine.available = 1) THEN
INSERT INTO user_machine VALUES (in_username, in_machine_id);
UPDATE machine SET machine.available = 0 WHERE machine.id = in_machine_id;
END IF;
COMMIT;
END;
谢谢。