如何在 PL/SQL 中使用 for 循环创建游标以传输记录?

How to create cursor using for loop in PL/SQL to transfer records?

使用 FOR 循环创建游标,但我唯一的问题是我们如何将已提取的每一行转移到另一个 table?可能吗?

使用 PL/SQL 的块并在我们从特定的 table 获取行之后包含一个 sequel 的 FOR 循环,之后我们想将已获取的行传输到其他 tables.

这是一个示例,它将 Scott 的 DEPT table 中的值 复制到 TEST table(也由 Scott 所有) ).

SQL> create table test (deptno number, dname varchar2(20), loc varchar2(20));

Table created.

SQL> begin
  2    for cur_r in (select deptno, dname, loc
  3                  from dept
  4                  where deptno <= 30
  5                 )
  6    loop
  7      insert into test (deptno, dname, loc)
  8        values (cur_r.deptno, cur_r.dname, cur_r.loc);
  9    end loop;
 10  end;
 11  /

PL/SQL procedure successfully completed.

SQL> select * from test;

    DEPTNO DNAME                LOC
---------- -------------------- --------------------
        10 ACCOUNTING           NEW YORK
        20 RESEARCH             DALLAS
        30 SALES                CHICAGO

SQL>