mysql 存储过程出错。
求高手看下为什么start transaction处报错。
谢谢!
SQL code
create procedure usp_SendSms
(
in p_mobilephone varchar(15),
in p_content varchar(400),
out p_id int(10)
)
begin
start transaction;
set p_id:=(select max(id) from guangbo for update);
set p_id:=p_id+1;
insert into guangbo(id,mobilephone,content) values(p_id,p_mobilephone,p_content);
commit;
end;
------解决方案--------------------
在5.5下测试没有问题
DELIMITER $$
CREATE PROCEDURE usp_SendSms
(
IN p_mobilephone VARCHAR(15),
IN p_content VARCHAR(400),
OUT p_id INT(10)
)
BEGIN
START TRANSACTION;
SET p_id:=(SELECT MAX(id) FROM guangbo FOR UPDATE);
SET p_id:=p_id+1;
INSERT INTO guangbo(id,mobilephone,content) VALUES(p_id,p_mobilephone,p_content);
COMMIT;
END;$$
DELIMITER ;
------解决方案--------------------
delimiter //
create procedure usp_SendSms
(
in p_mobilephone varchar(15),
in p_content varchar(400),
out p_id int(10)
)
begin
start transaction;
set p_id:=(select max(id) from guangbo for update);
set p_id:=p_id+1;
insert into guangbo(id,mobilephone,content) values(p_id,p_mobilephone,p_content);
commit;
end;
//
如果是在MYSQL命令行工具中用DELIMITER改变一下提交符,否则MYSQL工具看到分号就提交了你的语句。