'SyntaxcError on MySQL Query
I have created a procedure and ran it, but it is showing some syntax probem, can you help me?
My procedure is as:
**DELIMITER $$
CREATE PROCEDURE TestAdd(
in mODE varchar(10),
in Id int,
in AttName varchar(10),
in AttValues Varchar(10)
)
IF EXISTS (SELECT * FROM AttTable WHERE id=Id) THEN
SET Mode='Modify'
ELSE
SET Mode='Add'
Start Transaction
BEGIN
IF (mODE='Add') THEN
insert into atttable values (Id, AttName, AttValue);
ELSE (if Mode='Modify') then
update AttTable set AttName=AttName, AttValue= AttValue where Id=Id;
END IF
END
$$
Delimiter ;**
Solution 1:[1]
You need a BEGIN right after the parameter list at the beginning, and a matching END at the end of the procedure:
create procedure TestAdd(blah...)
BEGIN
...
END$$
Your first IF call is missing both THEN and END IF:
if exists ( select * from AttTable where id=Id) THEN
set...
ELSE
set...
END IF
Each of the statements needs to be terminated with a ;
set Mode='Modify';
set Mode='Add';
Start Transaction;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Joe Phillips |
