【问题标题】:ORA-00904: Invalid identifier when using forallORA-00904: 使用 forall 时标识符无效
【发布时间】:2023-03-13 15:06:01
【问题描述】:

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

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

【问题讨论】:

    标签: oracle plsql sql-insert ora-00904


    【解决方案1】:

    您在 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
    

    【讨论】:

    • 天哪,你是对的。我错过了。现在工作。非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-08
    • 2022-01-22
    • 2011-08-27
    • 2011-04-21
    • 2019-06-29
    • 2013-10-20
    • 2017-12-29
    相关资源
    最近更新 更多