Håkon Egset Harnes
Håkon Egset Harnes

Reputation: 15097

Syntax error when trying to create a procedure in mysql

I've just started out with procedures in MySql. I've read a lot of examples on how to implement them, but my code just doesnt seem to work. This could be stupidly simple, in which case i apologize for wasting your time, I'm just a bit in the dark as to what seems to be the problem.

create PROCEDURE 'InsertFriends'('userId' int) CHARSET utf8

BEGIN
insert into movieton_friends (prim,sec)
select 
    M.usr_id, U.ID
from movieton_friends_map as M
inner join movieton_users as U
    on M.fb_id = U.fb_id
left join movieton_friends as F
    on F.usr_id = M.usr_id
    and (   (M.usr_id = F.Prim and U.usr_id = F.Sec) 
        or  (M.usr_id = F.Sec and U.usr_id = F.Prim))
where M.usr_id = userId and F.prim is NULL;
END

PhpMyadmin/Mysql throws me this error:

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 ''InsertFriends'('userId' int) CHARSET utf8

BEGIN insert into movieton_frien' at line 1

As always, very helpfull.

Any hints, tricks or other help you might provide will be greatly appreciated!

PS: I tried a couple of variations with the DELIMITER statement, but didn't really make any difference. I can't really understand if its needed, and what its for, any enlightenment on this subject is also welcome!

Upvotes: 1

Views: 75

Answers (2)

newfurniturey
newfurniturey

Reputation: 38416

The error is specifically for the single-quotes you're using around the procedure and variable names:

create PROCEDURE 'InsertFriends'('userId' int) CHARSET utf8

In MySQL, you should surround them when backticks, not quotes:

create PROCEDURE `InsertFriends`(`userId` int) CHARSET utf8

Upvotes: 1

Mihai
Mihai

Reputation: 26784

Backticks for names not quotes or remove quotes.

Upvotes: 1

Related Questions