0
我已經試過在MySQL一個mysql程序中的內循環可以使用外循環
PROCEDURE fix()
BEGIN
DECLARE event_id_ INT;
DECLARE gate_number INT;
DECLARE l_done INT DEFAULT 0;
DECLARE curs_event_id CURSOR FOR SELECT DISTINCT event_id FROM history_15min;
DECLARE curs_gate_number CURSOR FOR SELECT DISTINCT gate_number
FROM history_15min WHERE event_id =event_id_;
(-- HERE IS THE PROBLEM - event_id_ IS BLANK THERE FOR THE INNER LOOP RETURNS NO RESULTS ....)
DECLARE CONTINUE HANDLER FOR NOT FOUND SET l_done=1;
OPEN curs_event_id;
event_loop : LOOP
FETCH curs_event_id INTO event_id_;
IF l_done=1 THEN LEAVE event_loop;
END IF;
OPEN curs_gate_number;
gate_loop : LOOP
FETCH curs_gate_number INTO gate_number;
IF l_done=1 THEN LEAVE gate_loop;
END IF;
insert into t value ('1');
END LOOP gate_loop;
CLOSE curs_gate_number;
SET l_done=0;
END LOOP event_loop;
CLOSE curs_event_id;
END
創建下列過程的結果有沒有辦法可以從第一個循環得到的結果是第二個循環中的變量?
你試過宣佈第一循環 – CHill60
DECLARE內第二光標在「OPEN curs_event_id;」之後不允許使用統計信息所以它不能這樣做 – yaniv
嵌套遊標應該在MySQL中可用 - 請參閱http://rpbouman.blogspot.com/2005/10/nesting-mysql-cursor-loops.html – CHill60