MySQL存储过程,游标未打开(1326)

时间:2014-09-09 07:58:41

标签: mysql sql stored-procedures

所以,我试图得到一些关于SELECT请求的结果,但每次我尝试调用它给我的程序时:

mysql> call canIDoThisSequenceSire(38,18);
ERROR 1326 (24000): Cursor is not open

我不知道为什么,我认为我的光标是正确打开的(我已经在其他商店程序上使用了这种代码骨架(从这里得到)并且它工作正常)并且在尝试找到有类似错误的人之后,我只有那些没有使用OPEN卷曲线的人。

这是代码

PROCEDURE `canIDoThisSequenceSire`(in idOpe INT, in idSeq INT)
BEGIN

DECLARE done INT default FALSE;
DECLARE isRoot,seqParent, seqDone INT;


DECLARE curl CURSOR FOR SELECT 
    se.isRoot, se.id_sequenceEnchainement
    FROM 
        tachesrealisees as tr
    JOIN
        collectiontache as ct
    ON
        ct.id = tr.id_collectiontache
    JOIN
        tache as t
    ON
        t.id=ct.id_tache
    JOIN 
        sequences as s
    ON 
        s.id = ct.id_sequences
    JOIN
        sequenceenchainement as se
    ON
        se.id_sequence=s.id
    WHERE 
        tr.id_operationsrealisees=idOpe
    AND 
        s.id=idSeq;

DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;

OPEN curl;


laBoucle : LOOP
    FETCH curl INTO isRoot, seqParent;
    IF isRoot THEN
        SET done = TRUE;
        LEAVE laBoucle;
    END IF;

    IF ISNULL(isRoot) then
        LEAVE laBoucle;
    END IF;

    CLOSE curl;

    END LOOP laBoucle;

    IF done THEN -- La séquence est à la racine
        SELECT 1 as result; 
    END IF;

    IF NOT done THEN 
            SELECT 0 as result; -- Please, come again
    END IF;

END

谢谢!

1 个答案:

答案 0 :(得分:0)

您正在关闭LOOP中的光标。

...
    IF ISNULL(isRoot) THEN
        LEAVE laBoucle;
    END IF;
    -- CLOSE curl;
END LOOP laBoucle;
CLOSE curl;
...