1

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!

2 Answers 2

1

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
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, this certainly did the trick! Little bit of facepalm though ;)
1

Backticks for names not quotes or remove quotes.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.