2015-03-03 41 views
1

我正嘗試使用從我的select中檢索到的id值,並且是我的循環在我的insert語句中所基於的值。 TEST_LOG表中select和第二列的id都是NUMBER(19,0)。當我用12345替換id時,它工作正常。有任何想法嗎?Oracle PLS-00382:表達式類型錯誤06550

BEGIN 
    FOR id IN 
    (SELECT id FROM t_sample where children is null) 
    LOOP 
    INSERT INTO TEST_LOG VALUES (my_sequence.nextVal, id, 'sample', current_timestamp); 
    END LOOP; 
END; 

錯誤:

Error starting at line : 6 in command - 
BEGIN 
     FOR id IN 
     (SELECT id FROM t_sample where children is null) 
     LOOP 
     INSERT INTO TEST_LOG VALUES (my_sequence.nextVal, id, 'sample', current_timestamp); 
     END LOOP; 
    END; 
Error report - 
ORA-06550: line 5, column 69: 
PLS-00382: expression is of wrong type 
06550. 00000 - "line %s, column %s:\n%s" 
*Cause: Usually a PL/SQL compilation error. 
*Action: 
+1

我應該在插入時將id引用爲id.id' – Sathya 2015-03-03 06:34:16

回答

4

的困惑是可以理解的。 你用這種方式寫得好,錯誤就會發光。

... 
FOR record IN 
     (SELECT id FROM t_sample where children is null) 
     LOOP 
     INSERT INTO TEST_LOG VALUES (my_sequence.nextVal, record.id, 'sample', current_timestamp); 
     END LOOP; 
... 
+0

感謝Florin Ghita完美的工作。 – c12 2015-03-03 06:39:39