我想知道是否有人可以帮助我使用这个SP,我不知道为什么,但程序只插入select内部de Insert语句的第一个结果(大约20行)。我做错了什么?
DELIMITER $$
DROP PROCEDURE IF EXISTS `sp_tine_tb_temp_month`$$
CREATE
/*[DEFINER = { user | CURRENT_USER }]*/
PROCEDURE `db_sumarizados`.`sp_tine_tb_temp_month`()
BEGIN
DECLARE no_more_rows BOOLEAN DEFAULT FALSE;
DECLARE a CHAR(16);
DECLARE b DATE;
DECLARE cur CURSOR FOR SELECT SITE_NE_NAME, DATE FROM unl_tb_ecl_stat_hh WHERE DATE BETWEEN '2014-04-01' AND '2014-04-30' GROUP BY SITE_NE_NAME, DATE HAVING COUNT(*) < 24;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET no_more_rows := TRUE;
CREATE TEMPORARY TABLE IF NOT EXISTS sitios_elegidos (
SITE_NE_NAME CHAR(16), FECHA DATE, HORA TIME
);
OPEN cur;
read_loop: LOOP
FETCH cur INTO a, b;
IF no_more_rows THEN
LEAVE read_loop;
END IF;
INSERT INTO sitios_elegidos (SITE_NE_NAME, FECHA, HORA) SELECT SITE_NE_NAME, FECHA, HORA FROM time_intervals i LEFT JOIN tb_de_pruebas p ON i.fecha = p.DATE AND i.hora = p.TIME WHERE SITE_NE_NAME = a AND DATE = b;
END LOOP;
CLOSE cur;
END$$
DELIMITER ;
答案 0 :(得分:0)
SET no_more_rows = FALSE;
......就在......之前......
END LOOP;
否则,如果INSERT ... SELECT
找不到任何内容,则可能会在光标实际耗尽之前过早地使CONTINUE
处理程序跳闸并将值设置为TRUE
。