Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MySQL游标获取不工作_Mysql_Stored Procedures - Fatal编程技术网

MySQL游标获取不工作

MySQL游标获取不工作,mysql,stored-procedures,Mysql,Stored Procedures,我有以下用于实现Dijkstra最短路径算法的存储过程: CREATE PROCEDURE `Dijkstras`(IN `pids` VARCHAR(512), IN `startP` VARCHAR(8), IN `endP` VARCHAR(8), OUT `dist` DECIMAL(20,10), OUT `eset` VARCHAR(1024)) BEGIN DECLARE currentP VARCHAR(4); DECLARE finished INT DEFAULT 0; DE

我有以下用于实现Dijkstra最短路径算法的存储过程:

CREATE PROCEDURE `Dijkstras`(IN `pids` VARCHAR(512), IN `startP` VARCHAR(8), IN `endP` VARCHAR(8), OUT `dist` DECIMAL(20,10), OUT `eset` VARCHAR(1024))
BEGIN
DECLARE currentP VARCHAR(4);
DECLARE finished INT DEFAULT 0;
DECLARE pt_from, pt_to int;
DECLARE pt_dist decimal(20,10);
DECLARE done INT DEFAULT 0;

DECLARE cur2 CURSOR FOR 
    select F.id as `from`, T.id as `to`, dist(F.lat, F.lng, T.lat, T.lng) 
      as dist
    from   sampledata F, sampledata T
    where  F.id < T.id and 
           find_in_set(convert(F.id, char(10)), pids) and
           find_in_set(convert(T.id, char(10)), pids) 
    order by dist;
  DECLARE CONTINUE HANDLER FOR not found SET done = 1; 

    SET currentP= startP;
  SET eset = '';
  SET dist = 0;


  SET done=0;
  OPEN cur2; -- this finds pariwise distances in miles.
  REPEAT 
    FETCH cur2 INTO pt_from, pt_to, pt_dist; 
    SET dist= dist+pt_dist;
        SET eset= CONCAT(eset, ',');
    IF(currentP=pt_from OR currentP=pt_to) AND 
    (IN_SET(pt_from,pids) AND IN_SET(pt_to,pids))  THEN
        BEGIN
            SET dist= dist+ pt_dist;
            SET pids= REMOVE_MEMBER(currentP, pids);
            SET eset = concat(eset, ',', concat(pt_from, ':', pt_to));
                IF left(eset, 1) = ',' then 
                    SET eset = substring(eset, 2); -- remove extra comma.
                END IF;
            IF currentP=pt_from THEN
                SET currentP=pt_to;
            ELSE 
                SET currentP=pt_from; 
            END IF;
            IF currentP= endP THEN
            SET finished= 1;
            END IF;
     END;
      END IF;
         UNTIL done 

  END REPEAT; 
  CLOSE cur2;


END
我的问题是光标不能正常工作。当我将当前行提取到pt_from、pt_to和pt_dist中时,我得到的都是空值。sampledata表正确存储在数据库中,pids中的所有点ID也存储在sampledata表中。另外,这段代码适用于另一个过程,但在这里重用它是行不通的


有人知道我做错了什么吗?

错误是我传入了像这样的点ID“12、15、18”,中间有空格。MySQL在解析字符串时统计空格,表中的id没有空格。传递字符串集的正确方式是'12,15,18'