1172 - 结果由mysql中的多行组成

时间:2014-12-30 03:41:59

标签: mysql

如何解决此问题(结果由mysql中的多行组成)

 DROP PROCEDURE IF EXISTS `doMarksApplication`;
 CREATE PROCEDURE `doMarksApplication`(
 in  kuser varchar(20),
 out idpro int(11))
 SP:BEGIN
   declare no_more_rows  int  default FALSE;
   declare total_marks   decimal(10,2) default 0;
   declare idfor  int(11)       default 0; 
   declare sskod  int(5)        default getCurSession();
   declare bdata  int(5)        default 0;
   declare nopmh  varchar(20);
   # Data PB [Permohonan Baru] DM [Proses Pemarkahan] 
   declare cur1 cursor for
   select ind_nopmh from pinduk 
   left join pprses on pro_nopmh = ind_nopmh
   where ind_sskod = sskod and
   concat(pro_stats,pro_statp) in ('PB','DM') and
   not exists (select mar_idnum from pmrkah where mar_nopmh = ind_nopmh)
   order by ind_nopmh;
   declare continue handler for not found set no_more_rows = TRUE;

   begin
        select count(ind_nopmh) into bdata 
        from pinduk 
        left join pprses on pro_nopmh = ind_nopmh
        where ind_sskod = sskod and
              concat(pro_stats,pro_statp) in ('PB','DM') and
              not exists (select mar_idnum from pmrkah where mar_nopmh = ind_nopmh);
      end;

      begin
        select count(for_idnum) into idfor from xkod_markah_00_formula
        where for_stats = 'A' and
              curdate() between for_tkhdr and for_tkhhg;
      end;

      if idfor = 1 and sskod <> 0 then
        begin
          select for_idnum into idfor from xkod_markah_00_formula
          where for_stats = 'A' and
                curdate() between for_tkhdr and for_tkhhg;
        end;

        begin
          insert into pprmar
          (pma_tkmla,pma_msmla,pma_puser,pma_sskod,pma_idfor,pma_bdata)
          values
          (curdate(),curtime(),kuser,sskod,idfor,bdata);
        end;

        begin
          select last_insert_id() into idpro;
        end;

        open cur1;    
        LOOP1:loop    
          fetch cur1 into nopmh;

          if no_more_rows then
            close cur1;
            leave LOOP1;
          end if; 

          begin
            call getMarksAnakPerak(nopmh,@total_perak);
            call getMarksAkademik(nopmh,@total_akdmk);
            call getMarksSosioekonomi(nopmh,@total_sosio);
          end;

          set total_marks = @total_perak + @total_akdmk + @total_sosio;

          begin
            insert into pmrkah
            (mar_idpro,mar_nopmh,mar_idfor,mar_perak,mar_akdmk,mar_sosio,mar_total)
            values
            (idpro,nopmh,idfor,@total_perak,@total_akdmk,@total_sosio,total_marks);
          end;

          begin
            update pprses 
            set pro_stats = 'D',
                pro_statp = 'M',
                pro_tkmsk = curdate(),
                pro_msmsk = curtime(),
                pro_kuser = kuser
            where pro_nopmh = nopmh;
          end;

        end loop; 

        begin
          update pprmar
          set pma_tktmt = curdate(),
              pma_mstmt = curtime()
          where pma_idnum = idpro;
        end;
      end if;
 END;

1 个答案:

答案 0 :(得分:1)

我已经在mysql中编程了15年,这很容易成为我见过的最混乱的存储过程。

尽管如此,你的问题的一个可能的地方就在这里

select for_idnum into idfor from xkod_markah_00_formula
  where for_stats = 'A' and
        curdate() between for_tkhdr and for_tkhhg;

我知道这似乎不是原因,但是如果不知道您调用的其他三个存储过程的内容,那么这是唯一的候选者。你应该为它添加一个限制1,并为从表中读取的每个select into语句(即不是sum()或count()等...)添加限制1,因为它总是有可能导致错误你是看到。

select for_idnum into idfor from xkod_markah_00_formula
  where for_stats = 'A' and
        curdate() between for_tkhdr and for_tkhhg limit 1;

此外,您应该注释掉三个存储过程调用,并查看错误是否消失。我的猜测是问题是那些存储过程之一,因为类似于上面的select into在结果集中有多个行但是没有使用限制1并且没有正确过滤。