なぜ「type = 1」が無視されているのか、一生理解できません。上記でタイプが設定されており、タイプが 1 または 2 であることを確認しました。タイプ = 5 に設定しても、if ステートメント内のすべてを実行できます。if type = 1 then を無視した場合です。if ステートメントを mysql にネストできますか?
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