Не могу понять где ошибка в MySQL. Все время вылетает QL Error [1064] [42000]
Скрипт не запускается, все время выдает:
SQL Error [1064] [42000]: 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 'DELIMITER // create procedure sp_friendship_offers(in for_user_id BIGINT UNSI' at line 3
В чем ошибка, плиз, хелп.
Код:
drop procedure if exists sp_friendship_offers;
DELIMITER //
create procedure sp_friendship_offers(in for_user_id BIGINT UNSIGNED)
begin
select p2.user_id
from profiles p1
join profiles p2
on p1.hometown = p2.hometown
where p1.user_id = for_user_id
and p2.user_id <> for_user_id
union
select uc2.user_id
from users_communities uc1
join users_communities uc2
on uc1.community_id = uc2.community_id
where uc1.user_id = for_user_id
and uc2.user_id <> for_user_id
union
select fr3.target_user_id
from friend_requests fr1
join friend_requests fr2
on (fr1.target_user_id = fr2.initiator_user_id
or fr1.initiator_user_id = fr2.target_user_id)
join friend_requests fr3
on (fr3.target_user_id = fr2.initiator_user_id
or fr3.initiator_user_id = fr2.target_user_id)
where (fr1.initiator_user_id = for_user_id or fr1.target_user_id = for_user_id)
and fr2.status = 'approved'
and fr3.status = 'approved'
and fr3.target_user_id <> for_user_id
order by rand()
limit 5;
end
//
DELIMITER ;