2016-11-15 119 views
0

我的光標正在處理第一條記錄並出來。這不是第二張唱片。可能是什麼問題?以下是我的代碼:MariaDB光標循環問題

有超過600,000行要處理。當我執行選擇查詢時,它顯示了正確的行數,但循環不起作用。

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

任何建議,如果我在這裏做錯了什麼? – 44KF

回答

-1

CURSORs通常是一個錯誤。你不能簡單地做這個一個聲明,沒有光標?

UPDATE StockData 
    SET ... 
    WHERE PriceDate > '2016-06-30'; 

f_20DayAvgOf50DayFactor(etc)是UDF還是存儲函數?

綜合指數需要

INDEX(symbol, PriceDate) 
+1

雖然這個答案也許是一種替代方法,但它甚至不是對這個問題的遠程答案。 – ericWasTaken