ORA-00904:使用forall时标识符无效

时间:2015-11-20 17:42:16

标签: oracle plsql sql-insert ora-00904

当我运行以下块时,我收到错误:

ORA-00904: Invalid identifier in "forall".

有人可以帮我解决一下吗?

列“ID”是12c标识列,因此编号。

drop table t1 cascade constraints purge;

create table t1 (
  c1  number
);

set serveroutput on;

declare
  type l_t2 is table of number;
  l_c1 l_t2;
begin
  select ID
    bulk collect into l_c1
    from IDTABLE;

  dbms_output.put_line('Number of records: ' || sql%rowcount);

  forall i in l_c1.first..l_c1.last
    insert into t1 values l_c1(i);
end;
/

1 个答案:

答案 0 :(得分:2)

您在values子句中的PL / SQL表引用周围缺少括号。改变这一行:

    insert into t1 values l_c1(i);

    insert into t1 values (l_c1(i));

没有它们,它认为l_cl是某种类型的模式级对象,它不存在;因此你看到的错误。它们有效:

set serveroutput on;
declare
  type l_t2 is table of number;
  l_c1 l_t2;
begin
  select ID bulk collect into l_c1 from IDTABLE;
  dbms_output.put_line('Number of records: ' || sql%rowcount);
  forall i in l_c1.first..l_c1.last
    insert into t1 values (l_c1(i));
end;
/

PL/SQL procedure successfully completed.

Number of records: 2