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

ORA-00904: Invalid identifier when using forall

当我运行下面的块时,我得到错误:

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;
/

您在值子句中缺少 PL/SQL table 引用周围的括号。更改此行:

    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