0

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

2

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.