oracle - 如何在 PL/SQL 中使用 for 循环创建游标来传输记录?
问题描述
使用 FOR 循环创建游标,但我唯一的问题是我们如何将已获取的每一行转移到另一个表中?是否可以?
在我们从特定表中获取行之后,使用 PL/SQL 块并包含一个 FOR 循环,之后我们希望将已获取的行转移到其他表中。
解决方案
这是一个将Scott 表中的值复制DEPT
到表中的示例TEST
(也由 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>
推荐阅读
- ios - 在 UITextView 顶部插入(附加)文本 - Swift
- scala - 当我编写 zipInputStream 时在 S3 中获取 0KB 文件
- r - 检查 write_xlsx 是否已正确执行并且文件是否已写入
- amazon-ec2 - 将 scylla 集群切换到大型 aws 实例的简单方法
- sql - 为什么没有在 SQL Server 2008 (Visual Studio 2010) 中创建用户实例?
- python - 是否可以将两个预先存在的数据库合并到一个前端?
- c# - C#异步LCD写
- angular - Angular github 页面路径具有重复的应用程序名称
- django - 如何在保存模型方法 DJANGO 中获取绝对 url?
- angular - Prime NG 的可编辑表上的奇怪行为