首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在同一块中声明的重复处理程序块

在同一块中声明的重复处理程序块
EN

Stack Overflow用户
提问于 2016-05-11 09:01:30
回答 1查看 2K关注 0票数 1

嗨,我正在写一个mysql过程,我一次使用两个游标,在实现这个过程时,面临着同一个块问题中定义的重复处理程序。我无法调试和纠正它。请帮帮我。

代码语言:javascript
运行
复制
DELIMITER $$
CREATE PROCEDURE chainReaction 
(
    in p_qry_stmt int,OUT procstatus varchar(500)
) 
BEGIN 
declare v_Count int(11);
    declare final_id  int DEFAULT 0;
        declare final_id2  int DEFAULT 0;
     DECLARE cust_id12 INT ;
       DECLARE aff_cust_id12 INT  ;
     DECLARE done int DEFAULT 0;
   declare v_col1 int;

  DECLARE cur2 CURSOR FOR select cust_id from tmp_Cust_Algmnt_Cust_Aff_Child  ;

  DECLARE cur1 CURSOR FOR select cust_id,aff_cust_id
from    (select * from t_aff_load
         order by cust_id,aff_cust_id) products_sorted,
        (select @pv := v_col1) initialisation
where   find_in_set(cust_id, @pv) > 0
and     @pv := concat(@pv, ',', aff_cust_id);

   /* declare continue handler for sqlstate '02000' set done = 1;*/

    DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; 



/*
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;*/


DECLARE CONTINUE HANDLER FOR NOT FOUND SET @isNOTFOUND := 0 ;



    DECLARE EXIT HANDLER FOR SQLEXCEPTION
   BEGIN
      GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE, @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
      SET @full_error = CONCAT("ERROR ", @errno, " (", @sqlstate, "): ", @text);
      set @isTrue = @full_error;
        insert into t_log(str_sstring) values(concat("chainReaction Execution Time: ", now() ," Exception :", @isTrue));
    SET procstatus:= @isTrue;
   END;




  DROP TABLE IF EXISTS tmp_Cust_Algmnt_Cust_Aff_Child;
  CREATE TEMPORARY TABLE tmp_Cust_Algmnt_Cust_Aff_Child (
   SeqNo bigint(20) NOT NULL PRIMARY KEY Auto_Increment ,
   cust_id int(11) NOT NULL,
   cust_algmnt_id bigint(20) NOT NULL
  );


 SET @isNOTFOUND := 1;

  SET @strQryStmt := CONCAT("INSERT INTO tmp_Cust_Algmnt_Cust_Aff_Child( cust_id, cust_algmnt_id )  ", p_qry_stmt);
  PREPARE QRYSTMT  FROM @strQryStmt;
  EXECUTE QRYSTMT;




    truncate table results_acc;
    truncate table results_prof;


OPEN cur2;

 repeat 
         fetch cur2           into  v_col1;
        /*   if no_more_rows1 then
               close cursor1;       
        leave LOOP1;
           end if;*/
  if not done then
  OPEN cur1;
   block2: BEGIN
               declare v_col2 int;
   DECLARE CONTINUE HANDLER FOR NOT FOUND SET doneLangLat = 1;

   repeat 
    FETCH cur1 INTO cust_id12,aff_cust_id12;
   if not doneLangLat then
    /* SET final_id = (select count(*) from t_cust where cust_id=cust_id12 and category_id=1);*/

  SET final_id2 = (select count(*) from t_cust where cust_id=aff_cust_id12 and category_id=1);
 if(final_id2>0) then
      insert into results_acc (cust_id1,aff_cust_id1)values(cust_id12,aff_cust_id12);  

      ELSE
       insert into results_prof (cust_id1,aff_cust_id1)values(cust_id12,aff_cust_id12);  

      end if;
      end if;
    until doneLangLat end repeat;
    END block2;
    close cur1;  
 end if;
    until done end repeat;
    close cur2;   

    DROP TABLE tmp_Cust_Algmnt_Cust_Aff_Child;

END$$
DELIMITER ;
EN

回答 1

Stack Overflow用户

发布于 2018-04-02 23:02:00

您正在复制处理程序块。要解决这个问题,您需要删除一个游标处理程序声明。

请查看手册Mysql游标

游标声明必须出现在处理程序声明之前以及变量和条件声明之后。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37157756

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档