当前位置:网站首页>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;

边栏推荐
- Flutter distribution
- A summary of practical websites that won't brighten people's eyes
- Using the primitive root of module m to judge and solve
- [recommended collection] MySQL 30000 word essence summary + 100 interview questions (I)
- 6、 Pinda general permission system__ pd-tools-log
- 【加密周报】加密市场有所回温?寒冬仍未解冻 盘点上周加密市场发生的重大事件
- Transfer guide printing system based on C language design
- 23.8 using the applicationrunner or commandlinerunner to implement applicationrunner and commandlinerunner
- 【搜索专题】看完必会的搜索问题之洪水覆盖
- 基于C语言的哈夫曼转化软件
猜你喜欢

Grid segmentation

OA项目之我的会议(会议排座&送审)

KV database based on raft consensus protocol

keepalived双机热备

Xshell batch send command to multiple sessions

Mysql8 one master one slave +mycat2 read write separation

22-07-16 personal training match 3 competition experience

【加密周报】加密市场有所回温?寒冬仍未解冻 盘点上周加密市场发生的重大事件

Mycat2 deploy master-slave MariaDB

Using the primitive root of module m to judge and solve
随机推荐
KV database based on raft consensus protocol
2022-7-4 personal qualifying 1 competition experience
Poor English, Oracle OCP or MySQL OCP exam can also get a high score of 80 points
Problems caused by slivereappbar
请问flink sql client 在sink表,有什么办法增大写出速率吗。通过sink表的同步时
[abstract base class inheritance, DOM, event - learning summary]
Kotlin variables and constants
Spark scheduling analysis
IC's first global hacking bonus is up to US $6million, helping developers venture into web 3!
Oracle 19C OCP 1z0-082 certification examination question bank (19-23)
QT note 1
Flutter compilation fails
【FreeSwitch开发实践】使用SIP客户端Yate连接FreeSwitch进行VoIP通话
[time complexity, space complexity]
Seq2seq and attention model learning notes
Xtrabackup appears' flush no '_ WRITE_ TO_ BINLOG TABLES‘: 1205 (HY000) Lock wait timeout exceeded;
Excel find duplicate lines
P1825 [USACO11OPEN]Corn Maze S
为什么要在时钟输出上预留电容的工位?
Write common API tools swagger and redoc