1
커서에서 가져온 데이터가 NULL입니다. 그러나 내 쿼리 select id from Projects
반환 행 수가 맞습니다. 프로 시저 루프에 select 문을 넣어 디버깅했습니다. id에 대해 null을 반환합니다. 나는 이것을 따라 갔다. [https://dev.mysql.com/doc/refman/5.5/en/cursors.html] 이 코드에 무슨 문제가 있습니까?null 값을 가져 오는 MySQL 커서
DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `ReportDiffProDiffFinYear`()
BEGIN
DECLARE id INT;
DECLARE sqlstr varchar(10000) default "select financialYear as 'name' ";
DECLARE done INT DEFAULT FALSE;
DECLARE cur1 CURSOR FOR select id from Projects; /* My CURSOR QUERY*/
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
OPEN cur1;
read_loop: LOOP
FETCH cur1 INTO id;
select id;
IF done THEN
LEAVE read_loop;
END IF;
set sqlstr = concat(sqlstr, ", sum(if(projects_id=",id,",0,1)) ");
END LOOP;
CLOSE cur1;
set @sqlstr = concat(sqlstr," from (select * from WaterPoints where status='Waterpoint Complete') as wp, (select id,financialYear from ProjectDetails) as pd where pd.id=wp.projectDetails_id group by pd.financialYear");
prepare stmt from @sqlstr;
execute stmt;
deallocate prepare stmt;
END
감사합니다. 그것은 완벽하게 작동했습니다. –