以下存储过程在我的本地系统中编译但在NetServer中失败。当变量'Target'(limit 0,Target;)被替换为数字时,它很有效,比如说(限制0,100;)但是在使用变量时会出错。
CREATE DEFINER=`root`@`localhost` PROCEDURE `Sp_AllocateScripts`(IN `QuestionId` INT, IN `ScriptType` INT, IN `Etype` CHAR(1), IN `GroupCount` INT)
DETERMINISTIC
BEGIN
DECLARE UserId,Target int;
DECLARE EvalType char(1);
DECLARE no_more_prefrences int DEFAULT 0;
DECLARE cur CURSOR FOR select A.nUserId as User, A.nTargetScripts-A.
nAllocatedScripts as Diff,cEvaluationType from tEvaluatorGroupDetails A inner join tEvaluatorGroup B on B.nGroupId=A.nGroupId where B.nQuestionId=QuestionId and A.cHeadUser='N' and A.cApproved='Y' and (A.nTargetScripts-A.nAllocatedScripts)>0;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET no_more_prefrences=1 ;
OPEN cur;
FETCH cur into UserId,Target,EvalType;
REPEAT
if Etype='M' then
if GroupCount=0 then
insert into tScriptsDetails (nScriptId,nUserId,cEvaluatedImage, cEvaluatedImgType) select nScriptId,UserId,iScriptImage,iScriptImageType from tScripts where nQuestionId=QuestionId and nScriptId not in(select S.nScriptId from tScriptsDetails S inner join tScripts Scr on
S.nScriptId=Scr.nScriptId inner join tevaluatorgroup E on
Scr.nQuestionId=E.nQuestionId inner join tevaluatorgroupdetails EG
on E.nGroupId=EG.nGroupId and EG.nUserId=S.nUserId where E.cEvaluationType=EvalType and cReMark='N' ) and nZoneId not in(select nZoneId from tUserProfile where nUserId=UserId ) limit 0,Target;
elseif GroupCount>0 then
insert into tScriptsDetails (nScriptId,nUserId,cEvaluatedImage, cEvaluatedImgType) select nScriptId,UserId,iScriptImage,iScriptImageType from tScripts where nQuestionId=QuestionId and nScriptId not in(select S.nScriptId from tScriptsDetails S inner join tScripts Scr on
S.nScriptId=Scr.nScriptId inner join tevaluatorgroup E on
Scr.nQuestionId=E.nQuestionId inner join tevaluatorgroupdetails EG
on E.nGroupId=EG.nGroupId and EG.nUserId=S.nUserId where E.cEvaluationType=EvalType and cReMark='N' group by S.nScriptId having count(*)>= GroupCount) and nZoneId not in(select nZoneId from tUserProfile where nUserId=UserId ) limit 0,Target;
end if;
elseif Etype='S' then
if GroupCount=0 then
insert into tScriptsDetails (nScriptId,nUserId,cEvaluatedImage, cEvaluatedImgType) select nScriptId,UserId,iScriptImage,iScriptImageType from tScripts where nQuestionId=QuestionId and nScriptId not in(select S.nScriptId from tScriptsDetails S where cReMark='N' ) and nZoneId not in(select nZoneId from tUserProfile where nUserId=UserId ) limit 0,Target;
elseif GroupCount>0 then
insert into tScriptsDetails (nScriptId,nUserId,cEvaluatedImage, cEvaluatedImgType) select nScriptId,UserId,iScriptImage,iScriptImageType from tScripts where nQuestionId=QuestionId and nScriptId not in(select S.nScriptId from tScriptsDetails S where cReMark='N' group by S.nScriptId having count(*)>= GroupCount) and nZoneId not in(select nZoneId from tUserProfile where nUserId=UserId ) limit 0,Target;
end if;
end If;
FETCH cur into UserId,Target,EvalType;
UNTIL no_more_prefrences=1
END REPEAT;
CLOSE cur;
update tEvaluatorGroupDetails C inner join tEvaluatorGroup D on C.nGroupId=D.nGroupId set C.nAllocatedScripts=(select count(*) from tScriptsDetails A inner join tScripts B on B.nScriptId=A.nScriptId where B.nQuestionId=QuestionId and A.nUserId=C.nUserId group by A.nUserId) where D.nQuestionId=QuestionId;
END
有什么办法可以解决吗?或者想知道我在这里犯的是什么错误。