2012-01-03 80 views
0
FOR I = 1 TO 10 
    tRESNUM = ALLTRIM(STR(I)) 
    tRESCAS = 'tRESCAS'+tRESNUM   

    &tRESCAS = 0.00 

ENDFOR  

我將這個狐狸專業版代碼轉換爲MySQL存儲過程。如何在MySQL存儲過程中獲取循環值?

在FoxPro tRESCAS = 'tRESCAS' + tRESNUM給tRESCAS1,tRESCAS2 .. 和& tRESCAS給這tRESCAS1或tRESCAS1或...別的東西的價值。

例如

if I =1 => 

FOR I = 1 TO 10 
     tRESNUM = ALLTRIM(STR(1)) 
     tRESCAS = 'tRESCAS'+1  

     tRESCAS1 = 0.00   
ENDFOR 

If I =2 => 

FOR I = 1 TO 10 
     tRESNUM = ALLTRIM(STR(2)) 
     tRESCAS = 'tRESCAS'+2  

     tRESCAS2 = 0.00   
ENDFOR 

& tRESCAS自動採取tRESCAS值tRESCAS1或tRESCAS2這樣。

在存儲過程中我如何獲得這種類型的值? (存儲過程中的任何特殊變量,如&這個?)

這個細節就夠了嗎?

回答

3

看一看這個過程 -

PROCEDURE procedure1() 
BEGIN 

    DECLARE tRESCAS VARCHAR(255) DEFAULT ''; 
    DECLARE i INT DEFAULT 0; 

    DROP TEMPORARY TABLE IF EXISTS t; 
    CREATE TEMPORARY TABLE t(num INT, column1 VARCHAR(255)); 

    WHILE i < 10 DO 
    INSERT INTO t VALUES(i, CONCAT('tRESCAS', i)); 
    SET i = i + 1; 
    END WHILE; 

    -- Try to get fifth value 
    SELECT column1 FROM t WHERE num = 5; 

END 

所有的值存儲到臨時表。

執行過程:

CALL procedure1; 
+----------+ 
| column1 | 
+----------+ 
| tRESCAS5 | 
+----------+