Oracle PLS-00382:表达式类型错误06550

时间:2015-03-03 06:09:03

标签: oracle

我试图使用从我的select中检索到的id值,这是我的循环在我的insert语句中的基础。 select中的id和TEST_LOG表中的第二列都是NUMBER(19,0)。当我用12345替换id时,它工作正常。有什么想法吗?

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 个答案:

答案 0 :(得分: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;
...