简体   繁体   中英

mysql stored procedure syntax error :

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;

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM