stored procedure
なぜこれが機能しないのか、何が間違っているのか誰か教えてください。構文エラーが発生し続けます。
puserid and plimit
プロシージャで渡されるパラメータです。
DECLARE uid BIGINT;
DECLARE rangee TINYINT;
SET @uid = puserid;
SET @rangee = plimit * 15;
PREPARE STMT FROM
'IF((SELECT count(type) from notificationrecievers nr where
nr.status=0 and nr.recieverid=?) = 0) THEN
select nr.type,n.senderid,n.postid,u.name,nr.status
from
user u,notifications n,notificationrecievers nr where
nr.recieverid=? and u.userid=n.senderid and
nr.notificationid=n.notid order by n.notid desc
limit 15 OFFSET ?;
ELSE
select nr.type,n.senderid,n.postid,u.name,nr.status
from
user u,notifications n,notificationrecievers nr where
nr.recieverid=? and u.userid=n.senderid and nr.status=0 and
nr.notificationid=n.notid order by n.notid desc;
END IF;';
EXECUTE STMT USING @uid,@uid,@rangee,@uid;
これが私が得るエラーです。
Error Code: 1064. 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 'IF((SELECT count(type) from notificationrecievers nr where nr.status=0 and nr.r' at line 1