功能在Online Server的MYSQL中不起作用

时间:2015-01-19 17:21:00

标签: mysql

我的Mysql数据库中有这个功能。

DROP FUNCTION `taskLevel`;
CREATE DEFINER=`attariso`@`localhost` FUNCTION `taskLevel`(`added` DATETIME, `GivenID` INT(11)) RETURNS VARCHAR(1025) NOT DETERMINISTIC CONTAINS SQL SQL SECURITY DEFINER BEGIN
DECLARE lvl varchar(10);
DECLARE rv,q,queue,queue_children,front_id VARCHAR(1024);
DECLARE queue_length,pos INT;
SET rv = '';
SET queue = GivenID;
SET queue_length = 1;

WHILE queue_length > 0 DO
    SET front_id = queue;
    IF queue_length = 1 THEN
        SET queue = '';
    ELSE
        SET pos = LOCATE(',',queue) + 1;
        SET q = SUBSTR(queue,pos);
        SET queue = q;
    END IF;
    SET queue_length = queue_length - 1;

    SELECT IFNULL(qc,'') INTO queue_children
    FROM (SELECT GROUP_CONCAT(t_id) qc
    FROM tbl_tasks WHERE parent_id = front_id) A;

    IF LENGTH(queue_children) = 0 THEN
        IF LENGTH(queue) = 0 THEN
            SET queue_length = 0;
        END IF;
    ELSE
        IF LENGTH(rv) = 0 THEN
            SET rv = queue_children;
        ELSE
            SET rv = CONCAT(rv,',',queue_children);
        END IF;
        IF LENGTH(queue) = 0 THEN
            SET queue = queue_children;
        ELSE
            SET queue = CONCAT(queue,',',queue_children);
        END IF;
        SET queue_length = LENGTH(queue) - LENGTH(REPLACE(queue,',','')) + 1;
    END IF;
END WHILE;

RETURN rv;
END

我正在运行此查询

SELECT tsk.t_id,sh.task_id , taskLevel( `t_id` ) AS children FROM tbl_tasks tsk,tbl_sharedtasks sh WHERE sh.project_id=1 and sh.user_id=71 and tsk.t_id =sh.task_id

这在我的本地系统上工作正常,但是当我在在线服务器上运行时,则会出现此错误

 #2014 - Commands out of sync; you can't run this command now

有什么问题可以解决。

0 个答案:

没有答案