0

我有一个 SP 游标,它适用于所有数据集,除了一个。该 SP 中有嵌套的游标。光标是这样的:

...
BLOCK1: begin
DECLARE cur1 CURSOR FOR select date, value1, value2 from excel.tc where date >= first_mov and id_fk = idz order by date DESC;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
OPEN cur1;

read_loop_1: LOOP

    FETCH cur1 into datez, value1z, value2z;  

    IF done THEN
        'exit loop
...lots of code

END LOOP;
end BLOCK1;

我的嵌套游标遵循相同的模型,打开块并声明游标和处理程序。SP 的工作原理是使用一组特定的数据;游标不会遍历所有行,即使 CURSOR FOR SELECT 中的所有值都是正确的(我已经调试过了)。并且这些数据没有任何不同,除了行不是按date物理排序的。

有什么会导致这个问题吗?我正在使用 MySQL 5.0.26。

**编辑:一些数据来说明:

使用这组数据不起作用,光标停在第三行(按日期排序时,desc):

date        value1     value2    id_fk     id
2006-02-17  0.920000   1.000000  12        25
2006-12-22  0.912000   1.000000  12        26
2007-04-24  0.818000   1.000000  12        27
2004-07-30  0.013650   1.000000  12        820
2004-10-30  0.012280   1.000000  12        821
2004-12-31  0.008960   1.000000  12        822
2005-04-16  0.006350   1.000000  12        823
2005-12-23  0.000000   -20.00000 12        824
2005-12-23  0.630000   1.000000  12        825
2003-12-31  0.020480   1.000000  12        826
2004-04-24  0.000850   1.000000  12        827
4

1 回答 1

0

My problem was that I had a select into var... which returned null, and was considered a condition for NOT FOUND for the handler. This is well documented but I missed it somehow.

于 2012-11-29T17:22:12.670 回答