xcodemaddy
xcodemaddy

Reputation: 31

Insert,upadate in single Procedure in 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 corresponds 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 ;

Upvotes: 1

Views: 7953

Answers (2)

moinudin
moinudin

Reputation: 138347

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.

Upvotes: 1

sshet
sshet

Reputation: 1160

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

Upvotes: 0

Related Questions