当前位置:网站首页>pl/sql之集合-2
pl/sql之集合-2
2022-07-26 08:38:00 【赟文武】
bulk collect
弥补了select…into、cursor一次只能接收一行数据
select…into…与bulk collect
一、关键部分语法
select 列名 bulk collect into 集合变量名 from 表名;
二、简单示例
--输出emp表中所有人姓名
declare
--声明嵌套表类型a
type a is table of emp.ename%type;
--声明嵌套表类型a的承载变量b
b a;
begin
--将emp表中所有ename赋值给b嵌套表变量
select ename bulk collect into b from emp;
--循环输出嵌套表b中内容
for i in b.first..b.last loop
dbms_output.put_line(b(i));
end loop;
end;
--2
declare
--声明嵌套表类型a
type a is table of emp%rowtype;
--声明嵌套表类型a的承载变量b
b a;
begin
--将emp表中所有ename赋值给b嵌套表变量
select * bulk collect into b from emp;
--循环输出嵌套表b中内容
for i in b.first..b.last loop
dbms_output.put_line(b(i).ENAME);
end loop;
end;

cursor与bulk collect
一、关键部分语法
fetch 游标名 bulk collect into 集合变量名;
二、简单示例
declare
--声明一个名为a的游标
cursor a is select ename from emp;
--声明一个嵌套表类型
type b is table of emp.ename%type;
--声明一个承载嵌套表集合变量
c b;
begin
--打开游标
open a;
--匹配数据
fetch a BULK collect into c;
--关闭游标
close a;
--循环输出c中元素
for i in c.first..c.last loop
dbms_output.put_line(c(i));
end loop;
end;
--2
declare
--声明一个名为a的游标
cursor a is select * from emp;
--声明一个嵌套表类型
type b is table of emp%rowtype;
--声明一个承载嵌套表集合变量
c b;
begin
--打开游标
open a;
--匹配数据
fetch a BULK collect into c;
--关闭游标
close a;
--循环输出c中元素
for i in c.first..c.last loop
dbms_output.put_line(c(i).ename);
end loop;
end;

批量绑定forall
一、关键部分语法
forall 变量 in 集合变量名;
二、简单示例
--根据emp表中部门编号删除dept中信息
--隐式游标
begin
delete from dept where deptno in(select distinct deptno from emp);
end;
--批量绑定
declare
--声明嵌套表类型
type a is table of dept.deptno%type;
--声明承载嵌套表类型变量
b a;
--声明变量
c dept.deptno%type;
begin
--赋值
SELECT DISTINCT DEPTNO BULK collect INTO b FROM EMP;
--批量绑定
forall i in b.first..b.last
delete from DEPT where deptno=b(i);
end;

边栏推荐
- 【FreeSwitch开发实践】自定义模块创建与使用
- QT note 2
- 23.10 Admin features
- P3743 kotori的设备
- Leetcode and query question summary
- Oracle 19C OCP 1z0-082 certification examination question bank (19-23)
- Xshell batch send command to multiple sessions
- Oracle 19C OCP 1z0-082 certification examination question bank (7-12)
- 【FreeSwitch开发实践】使用SIP客户端Yate连接FreeSwitch进行VoIP通话
- 2022-7-8 personal qualifying 5 competition experience (supplementary)
猜你喜欢

Kotlin function

SSH,NFS,FTP

Kotlin program control

QSS add resource file of QT

Spark persistence strategy_ Cache optimization

MySQL 8.0 OCP (1z0-908) has a Chinese exam

Neo eco technology monthly | help developers play smart contracts

Excel find duplicate lines

Kotlin operator

Nodejs2day(nodejs的模块化,npm下载包,模块加载机制)
随机推荐
Excel delete blank lines
Which financial product has the highest yield in 2022?
MySQL 8.0 OCP 1z0-908 certification examination question bank 1
Special lecture 2 dynamic planning learning experience (should be updated for a long time)
After MySQL 8 OCP (1z0-908), hand in your homework
2022-7-6 personal qualifying 3 competition experience
[GUI] GUI programming; AWT package (interface properties, layout management, event monitoring)
Huffman transformation software based on C language
Mysql8 dual master and dual slave +mycat2 read / write separation
File management file system based on C #
Error handling response: Error: Syntax error, unrecognized expression: .c-container /deep/ .c-contai
Number of briquettes & Birthday Candles & building blocks
2022-7-8 personal qualifying 5 competition experience (supplementary)
[recommended collection] summary of MySQL 30000 word essence - partitions, tables, databases and master-slave replication (V)
Oracle 19C OCP 1z0-082 certification examination question bank (42-50)
[suggestions collection] summary of MySQL 30000 word essence - locking mechanism and performance tuning (IV) [suggestions collection]
QSS add resource file of QT
Lesson 3: gcc compiler
23.8 using the applicationrunner or commandlinerunner to implement applicationrunner and commandlinerunner
Flutter WebView three fingers rush or freeze the screen