1

我一生都无法理解为什么“type = 1”被忽略了。上面设置了类型,我已经验证了类型是 1 还是 2。我可以设置类型 = 5,它仍然会执行 if 语句中的所有内容。如果它忽略了 if type = 1 那么。你可以在mysql中嵌套if语句吗?

DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `select_player`(teamid INT)
BLOCK1: begin -- outer block
declare done INT default false;
declare type INT;
declare check_pos text;
declare curse2 cursor for select pos, sort1 from dutil_pos_sort;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done := TRUE;
open curse2;
rd_loop: LOOP
  fetch curse2 into check_pos, type;
  if done then
    leave rd_loop;
  end if;
BLOCK2: begin -- inner block
  declare done1 INT default false;
  declare pl_id, comp INT;
  declare dl_pos text;
  declare curse1 cursor for select p.player_id,substring_index(substring_index(p.pos,'/',1),'/',-1) as segment1 from dutil_players p,  dutil_picks k where k.player_id = p.player_id and k.team_id=teamid;
  DECLARE CONTINUE HANDLER FOR NOT FOUND SET done1 := TRUE;  
  open curse1;
  read_loop: LOOP
    fetch curse1 into pl_id, dl_pos;
    if done1 then
      leave read_loop;
    end if;
    if type = 1 then
      if dl_pos like concat("%",check_pos,"-","%") then
        select "MATCH",pl_id, dl_pos, check_pos;
        leave read_loop;
      else 
        select "NO MATCH", check_pos;
      end if;
    else
      if dl_pos like BINARY concat("%",check_pos,"%") then
        select "MATCH",pl_id, dl_pos, check_pos;
        leave read_loop;
      else
        select "NO MATCH", check_pos;
      end if;
    end if;
  end loop read_loop;
  close curse1;
  end BLOCK2;
end loop rd_loop;
close curse2;
end BLOCK1
4

0 回答 0