mysql 获取游标大小_MySQL获取下一个游标问题

我从

MySQL游标中获取值时遇到问题.

我创建一个临时表,它只是另一个表的副本(原始表有一个变量名,它作为过程的参数传递,因为MySQL不支持变量表名,我必须创建一个副本 – 不能直接使用原文).

临时表创建很顺利,应该在其中的所有数据都在那里.然后我定义一个游标来遍历我的临时表…但是当我尝试从一个while循环中的光标中获取时,我的变量没有填充来自“cursored”表的数据…其中大多数只是NULL,只有最后2个似乎在里面有正确的值.

这是我的代码块:

-- variables to be filled from the cursor

DECLARE id,rain,snow,hs,clouds,rain2,cape,status,done int;

DECLARE v_v,v_u double;

-- cursor declaration

DECLARE iter CURSOR FOR (SELECT id,cape,rain,snow,hstones,clouds,raining,wind_u,wind_v FROM temp_tbl);

DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;

-- drop the old temporary table if any

DROP TABLE IF EXISTS temp_tbl;

-- a statement to create the temporary table from a table with the specified name

-- (table_name is a parameter of the stored procedure this chunk is from)

SET @temp_table = CONCAT('CREATE TABLE temp_tbl AS SELECT * FROM ', table_name, ' WHERE 1');

-- prepare, execute and deallocate the statement

PREPARE ctmp FROM @temp_table;

EXECUTE ctmp;

DEALLOCATE PREPARE ctmp;

-- now the temp_table exists, open the cursor

OPEN iter;

WHILE NOT done DO

-- fetch the values

FETCH iter INTO id,cape,rain,snow,hs,clouds,rain2,v_u,v_v;

-- fetch doesnt work, only v_u and v_v variables are fetched correctly, others are null

-- ... further statements go here

END WHILE;

CLOSE iter;

FETCH语句中是否存在可能导致此类问题的类型检查?我的临时表中的列(源自原始列)只是小的int或tiny-int,所以这些列应该与我在fetch语句中使用的int完全兼容.最后两个是双打,但很奇怪只有这两个双打.即使是ID int列,也不是主键.

我使用dbForge Studio进入并调试我的程序,但这应该不是问题.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值