我的光标只处理第一条记录然后出来。它不会成为第二记录。可能是什么问题?以下是我的代码:
要处理的行数超过600,000。当我执行select查询时,它会向我显示正确的行数,但循环不起作用。
Delimiter $$
CREATE PROCEDURE p_updateHistory_1()
BEGIN
DECLARE v_symbol varchar(10);
DECLARE v_pricedate date;
DECLARE done BOOL DEFAULT FALSE;
DECLARE cur1 CURSOR FOR SELECT symbol, PriceDate
from StockData
where PriceDate > '2016-06-30'
order by symbol asc, PriceDate desc;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
OPEN cur1;
read_loop: LOOP
FETCH cur1 INTO v_symbol, v_pricedate;
If done THEN
LEAVE read_loop;
END IF;
Update StockData SET
20DayTPAvg = f_TP20avg(symbol,PriceDate),
20DayMFSum = f_20DayMFSum(symbol,PriceDate),
20DayVolumeSum = f_20DayVolumeSum(symbol,PriceDate),
MFFactor = f_20DayMFSum(symbol,PriceDate)/f_20DayVolumeSum(symbol,PriceDate),
50DayHighestHigh = f_50DayHighestHigh(symbol,PriceDate),
50DayLowestLow = f_50DayLowestLow(symbol,PriceDate),
50DayFactor = ((close-f_50DayLowestLow(symbol,PriceDate))/(f_50DayHighestHigh(symbol,PriceDate)-f_50DayLowestLow(symbol,PriceDate)))*100,
20DayAvgOf50DayFactor = f_20DayAvgOf50DayFactor(symbol,PriceDate),
50DayMAvg20DayBfr = f_20DayMAvg20DayBfr(symbol,PriceDate),
20DayAvgSqCh50DMA = f_20DayAvgSqCh50DMA(symbol,PriceDate),
20dStdDevOf50DayMovAvg = SQRT(f_20DayAvgSqCh50DMA(symbol,PriceDate)),
UpperBand = 50DayMovingAvg+2*SQRT(f_20DayAvgSqCh50DMA(symbol,PriceDate)),
LowerBand = 50DayMovingAvg-2*SQRT(f_20DayAvgSqCh50DMA(symbol,PriceDate)),
MidPointFactor = ((close-MidPoint)/(high-close))*100,
20DayAvgOfMPFactor = f_20DayAvgOfMPFactor(symbol,PriceDate)
Where symbol=v_symbol
And PriceDate=v_pricedate;
commit;
END LOOP;
CLOSE Cur1;
END $$
Delimiter ;
答案 0 :(得分:0)
我有同样的问题。 根据MariaDB文档,如果任何select语句不返回任何数据,则它将被视为“未找到”,并且根据处理程序Done变为true,因此停止获取游标。 似乎您正在使用许多功能。请检查是否有任何函数返回空结果。
答案 1 :(得分:-1)
CURSORs
通常是个错误。你不能简单地执行一个语句,没有游标吗?
UPDATE StockData
SET ...
WHERE PriceDate > '2016-06-30';
f_20DayAvgOf50DayFactor
(等)是UDF还是存储函数?
需要复合INDEX
INDEX(symbol, PriceDate)