游标过程出错

时间:2013-03-25 08:58:57

标签: mysql stored-procedures

很抱歉粘贴这么难看的代码。但是我无法帮助它。这是我使用光标的程序。

DELIMITER ##
CREATE PROCEDURE myproced()
BEGIN
  DECLARE arpt varchar(10);
  DECLARE cur CURSOR FOR SELECT DISTINCT name FROM lookup.airport;
  OPEN cur;

  read_loop: LOOP
  FETCH cur INTO arpt;

SELECT DISTINCT c.star_ident, c.fix_ident
  FROM corept.std_star_leg c
INNER JOIN
(SELECT star_ident,
       transition_ident,
       max(sequence_num) seq,
       route_type
  FROM corept.std_star_leg
 WHERE data_supplier = 'J'
 AND airport_ident = apt
GROUP BY star_ident, transition_ident
)b
 ON c.sequence_num=b.seq
 AND c.star_ident=b.star_ident
 AND c.transition_ident=b.transition_ident
 WHERE c.data_supplier='J'
 AND c.airport_ident=arpt
 AND NOT EXISTS

 (SELECT name, trans
  FROM skyplan_deploy.deploy_stars d
 WHERE     d.apt = arpt
       AND d.name != d.trans
       AND c.star_ident = d.name
       AND c.fix_ident = d.trans)

  UNION

 SELECT name, trans
  FROM skyplan_deploy.deploy_stars d
 WHERE apt = arpt
 AND name != trans
  AND NOT EXISTS

 (SELECT DISTINCT c.star_ident, c.fix_ident
  FROM    corept.std_star_leg c
       INNER JOIN
          (SELECT star_ident,
                  transition_ident,
                  max(sequence_num) seq,
                  route_type
             FROM corept.std_star_leg
            WHERE data_supplier = 'J'
            AND airport_ident = arpt
           GROUP BY star_ident, transition_ident) b
       ON     c.sequence_num = b.seq
          AND c.star_ident = b.star_ident
          AND c.transition_ident = b.transition_ident
 WHERE     c.data_supplier = 'J'
       AND c.airport_ident = arpt
       AND d.name = c.star_ident
       AND d.trans = c.fix_ident);

IF done THEN
  LEAVE read_loop;
END IF;

END LOOP;

CLOSE cur1;
END
##

实际上我说实时环境中的游标不是那么鼓励。执行上面的程序我没有得到数据库选择错误。也有人可以提供一种有效的方法来循环除了游标中的游标而不是mysql 。上述查询中的光标将包含大约30000个条目 谢谢。

如果我选择数据库,则给出错误1064

  

您的SQL语法有错误;检查手册   对应于您的MySQL服务器版本,以便使用正确的语法   在第1行'END ##'附近

0 个答案:

没有答案