我有一个mysql存储过程,它给了我以下错误: -
#1064 - 您的SQL语法出错;查看与您的MySQL服务器版本相对应的手册,以便在'set intoffer ='附近使用正确的语法'从家里选择max(offerid)'if(intoffer IS NULL)然后在第4行设置int'
我已在分隔符框中将分隔符设置为;。存储过程为
create procedure sp()
begin
declare intoffer int
set intoffer = 'select max(offerid) from home'
if(intoffer IS NULL) then
set intoffer=1
else
set intoffer=intoffer+1
insert into home(offerid,offerheader,offertext,offerimage,offerlink) values(intoffer,'d','d','d','d')
end;
答案 0 :(得分:1)
有一些语法和其他错误。试试这段代码 -
CREATE PROCEDURE sp()
BEGIN
DECLARE intoffer INT;
SELECT max(offerid) INTO intoffer FROM home;
IF (intoffer IS NULL) THEN
SET intoffer = 1;
ELSE
SET intoffer = intoffer + 1;
END IF;
INSERT INTO home (offerid, offerheader, offertext, offerimage, offerlink) VALUES (intoffer, 'd', 'd', 'd', 'd');
END