我正在循环访问MYSQL存储过程中的游标结果集。我面临着一个问题,即循环总是运行两次最后一个记录。这里是我的代码,如果我有3条记录,循环运行的4倍,如果是10条循环运行11次,等等。任何想法发生了什么这里MYSQL光标循环,运行一个额外的轮,为什么?
BEGIN
DECLARE not_found_creadit INT DEFAULT 0;
DECLARE cur_credit CURSOR FOR
SELECT customer_id, amount, status, user_type, employee, note FROM credit WHERE status = 'approved' AND customer_id = int_cust_id;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET not_found_creadit = 1;
OPEN cur_credit;
SET not_found_creadit = 0;
credit_loop : LOOP
IF not_found_creadit THEN
CLOSE cur_credit;
LEAVE credit_loop;
END IF;
FETCH cur_credit INTO vc_customer, dec_amount, vc_status, vc_user_type, vc_emp, vc_note;
SELECT vc_customer, dec_amount, vc_status, vc_user_type, vc_emp, vc_note;
......
......
END LOOP;
END;
手段?
这可能会帮助 - > [光标放在最后一行两次迭代( http://forums.mysql.com/read.php?102,155063,155063) – Kermit
是的,这真的有效。 Thanx – Thanu
链接现在缺失 – ejectamenta