简体   繁体   English

mysql存储过程语法错误:

[英]mysql stored procedure syntax error :

I have a mysql stored procedure which is giving me the following error:- 我有一个mysql存储过程,它给我以下错误: -

#1064 - You have an error in your SQL syntax; #1064 - 您的SQL语法有错误; 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 查看与您的MySQL服务器版本相对应的手册,以便在'set intoffer ='附近使用正确的语法选择来自home的if(offerid)if(intoffer IS NULL)然后在第4行设置int'

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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