0
votes

I have a mysql stored procedure which is giving me the following error:-

#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 'set intoffer = 'select max(offerid) from home' if(intoffer IS NULL) then set int' at line 4

I have set the delimiter in the delimiter box as ;.The stored procedure is

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;
1

1 Answers

2
votes

There were some syntax and other errors. Try this code -

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