1
declare
    cursor c_1 is select a.*, a.rowid from an_test a;

    type t_1 is table of an_test%rowtype;

    type l_row_id is table of UROWID;

    tab t_1; 

    row l_row_id;

begin
    open c_1;

    loop
        fetch c_1 bulk collect into tab, row limit 1000;
        ...
    end loop;
end;

我正在尝试执行上面的代码,但它给了我这样的错误:

PLS-00597:INTO 列表中的表达式“选项卡”类型错误。

有没有其他/替代方法可以做到这一点?

提前致谢。

4

4 回答 4

2

如果您可以在同一条记录中使用 rowid 进行管理,请将您的类型基于游标而不是表:

declare
    cursor c is
        select a.*, a.rowid
        from   customer a;

    type t is table of c%rowtype;
    tab t;

begin
    open c;
    fetch c bulk collect into tab limit 1000;
end;
于 2020-08-08T08:16:16.313 回答
0

应该是这样的:

SQL> set serveroutput on;
SQL> declare
  2    cursor c1 is select d.*, d.rowid from dept d;
  3    type t1r is record
  4      (deptno   number,
  5       dname    varchar2(20),
  6       loc      varchar2(20),
  7       rowid    urowid
  8      );
  9    type t1t is table of t1r;
 10    t1   t1t;
 11  begin
 12    open c1;
 13    fetch c1 bulk collect into t1;
 14    close c1;
 15
 16    for i in t1.first .. t1.last loop
 17      dbms_output.put_line(rpad(t1(i).dname, 15, ' ') ||' '|| t1(i).rowid);
 18    end loop;
 19  end;
 20  /
ACCOUNTING      AAAGvqAAEAAAAIUAAA
RESEARCH        AAAGvqAAEAAAAIUAAB
SALES           AAAGvqAAEAAAAIUAAC
OPERATIONS      AAAGvqAAEAAAAIUAAD

PL/SQL procedure successfully completed.

SQL>
于 2020-08-07T20:34:54.127 回答
0

在这种情况下,您不需要额外的 rowid 变量。只需, row fetch c_1 bulk collect into tab, row limit 1000;

应该很简单 fetch c_1 bulk collect into tab limit 1000;

于 2020-08-07T22:30:50.853 回答
0
SQL> set serveroutput on;
SQL> declare
       cursor c1 is select d.*, d.rowid from dept d;
       type t1r is record
         (deptno   number,

              dname    varchar2(20),

          loc      varchar2(20),
          rowid    urowid
         );
       type t1t is table of t1r;
       t1   t1t;
     begin
       open c1;
       fetch c1 bulk collect into t1;
       close c1;
   
       for i in t1.first .. t1.last loop
         dbms_output.put_line(rpad(t1(i).dname, 15, ' ') ||' '|| t1(i).rowid);
       end loop;
   end;
   /
于 2020-08-08T14:39:07.097 回答