0

我有这个存储过程,我在其中使用准备好的语句来执行两个查询。这是过程。

SET @uid    = puserid;
SET @rangee = plimit * 50;
SET @post = 'post';

PREPARE STMT FROM 
'
SELECT  notifications.postid,victims.victimid,friends.friendsname,notificationrecievers.status 

FROM friends,victims,notifications,notificationrecievers

WHERE victims.postid=notifications.postid 

AND notificationrecievers.notificationid=notifications.notid

AND notificationrecievers.recieverid=?

AND notifications.type=? 

AND friends.friendsid=victims.victimid

AND notificationrecievers.notificationid <=
(
   SELECT MAX(notid) FROM
   (
      SELECT n.notid 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 50 OFFSET ?
   )a
)
AND notificationrecievers.notificationid >=
(
   SELECT MIN(notid) FROM
   (
      SELECT n.notid 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 50 OFFSET ?
   )b
)
ORDER BY notifications.postid DESC;

UPDATE notificationrecievers 

SET notificationrecievers.status=1 

WHERE notificationrecievers.status=0
AND   notificationrecievers.recieverid=? 

AND

notificationrecievers.notificationid <=
(
     SELECT MAX(notid) FROM
     (
      SELECT n.notid 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 50 OFFSET ?
     )e
)   

AND

notificationrecievers.notificationid >=
(
     SELECT min(notid) FROM
     (
      SELECT n.notid 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 50 OFFSET ?
     )g
);

';
EXECUTE STMT USING @uid,@post,@uid,@rangee,@uid,@rangee,@uid,@uid,@rangee,@uid,@rangee;

当我在过程中运行此查询时,它给了我语法错误。但是当我通过提供硬编码值代替它直接使用它时,?它工作正常。为什么会发生这种情况?puserid并且plimit是我传递给这个过程的参数。

这是错误:

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 ';

UPDATE 
notificationrecievers 
SET notificationrecievers.st' at line 25
4

0 回答 0