开发者

Insert,upadate in single Procedure in mysql

开发者 https://www.devze.com 2023-02-03 07:30 出处:网络
im creating stored procedure in my sql but getting error,error shows as below,help me Error Descrption:You hve an error in your sql syntax: ckeck the manual that c开发者_C百科orresponds to your MYSQL

im creating stored procedure in my sql but getting error,error shows as below,help me Error Descrption:You hve an error in your sql syntax: ckeck the manual that c开发者_C百科orresponds to your MYSQL

server version fro the right syntax to use near 'END' at line 13

DELIMITER $$
DROP PROCEDURE IF EXISTS myhealthcamp.area $$
CREATE PROCEDURE myhealthcamp.area
(
  IN id INT,
  IN ar VARCHAR(45)
)
BEGIN
if exists (select area_id from area where area_id = id)
Then
  update area set areaname = ar where area_id=id;
else
  insert into area(area_id, areaname) values(id,ar);
END IF
END $$
DELIMITER ;


You're missing a ; in this line:

END IF

It should be:

END IF;

IF is a statement and all statements must end in semi-colons. This one's no different. See the MySQL documentation for IF.


DROP PROCEDURE IF EXISTS myhealthcamp.area $$
CREATE PROCEDURE myhealthcamp.area
(
  IN id INT,
  IN ar VARCHAR(45)
)
BEGIN
if exists (select area_id from area where area_id = id)
Then
  update area set areaname = ar where area_id=id;
else
  insert into area(area_id, areaname) values(id,ar);
END IF;

semicolon missing

Thanks Sanil

0

精彩评论

暂无评论...
验证码 换一张
取 消