如何在mysql中的另一个if语句中嵌套if语句

时间:2013-05-03 06:59:22

标签: mysql mysql-workbench

我不能为我的生活理解为什么“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

0 个答案:

没有答案