2013-02-03 3 views
0

제발 아무도 왜이 stored procedure이 작동하지 않는지, 왜 내가 wrong.It 구문 오류를 계속하고 있는지 말해 줄 수 있습니다.준비된 문 쿼리 구문 오류

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 
+0

나는이 질문을 편집했다. – Mj1992

+0

언제이 오류가 발생합니까? PROCEDURE를 생성하는 동안 또는 EXECUTING 중에 실행합니까? 나는이 절차를 잘 만들 수 있었다. – SparKot

+0

프로 시저를 실행하는 동안이 오류가 발생합니다. – Mj1992

답변

0

준비된 문에 DML 만 사용할 수 있습니다. 당신은 당신의 상태를 평가하기 전에 몇 가지 쿼리를 실행할 수있는이

IF condition THEN 
    set @q = 'your query text' 
ELSE 
    set @q = 'another query' 
END IF; 

PREPARE stmt FROM @q 
EXECUTE stmt using ... 
DEALLOCATE PREPARE stmt 

처럼 뭔가를 할 수 있습니다. 도움이 되었으면

+0

thnx가 도움이됩니다. – Mj1992