我有一个mysql存储过程,它给我以下错误:
#1064-您的SQL语法有误;检查与您的MySQL服务器版本对应的手册以获取正确的语法,以在“ set inffer ='select home(select max(offerid)from home)if(intoffer IS NULL)then set 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;
最佳答案
有一些语法和其他错误。试试这个代码-
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