当前位置:网站首页>Set of pl/sql -2
Set of pl/sql -2
2022-07-26 08:47:00 【Yun Wenwu】
bulk collect
Make up for select…into、cursor Only one row of data can be received at a time
select…into… And bulk collect
One 、 The key part is grammar
select Name bulk collect into Collection variable name from Table name ;
Two 、 A simple example
-- Output emp Names of all persons in the table
declare
-- Declare nested table types a
type a is table of emp.ename%type;
-- Declare nested table types a Bearing variable of b
b a;
begin
-- take emp All in the table ename Assign a value to b Nested table variables
select ename bulk collect into b from emp;
-- Loop out nested tables b Chinese content
for i in b.first..b.last loop
dbms_output.put_line(b(i));
end loop;
end;
--2
declare
-- Declare nested table types a
type a is table of emp%rowtype;
-- Declare nested table types a Bearing variable of b
b a;
begin
-- take emp All in the table ename Assign a value to b Nested table variables
select * bulk collect into b from emp;
-- Loop out nested tables b Chinese content
for i in b.first..b.last loop
dbms_output.put_line(b(i).ENAME);
end loop;
end;
cursor And bulk collect
One 、 The key part is grammar
fetch You name bulk collect into Collection variable name ;
Two 、 A simple example
declare
-- Declare a a The cursor of
cursor a is select ename from emp;
-- Declare a nested table type
type b is table of emp.ename%type;
-- Declare a set variable that hosts nested tables
c b;
begin
-- Open cursor
open a;
-- Matching data
fetch a BULK collect into c;
-- Close cursor
close a;
-- Cyclic output c Medium element
for i in c.first..c.last loop
dbms_output.put_line(c(i));
end loop;
end;
--2
declare
-- Declare a a The cursor of
cursor a is select * from emp;
-- Declare a nested table type
type b is table of emp%rowtype;
-- Declare a set variable that hosts nested tables
c b;
begin
-- Open cursor
open a;
-- Matching data
fetch a BULK collect into c;
-- Close cursor
close a;
-- Cyclic output c Medium element
for i in c.first..c.last loop
dbms_output.put_line(c(i).ename);
end loop;
end;
Batch binding forall
One 、 The key part is grammar
forall Variable in Collection variable name ;
Two 、 A simple example
-- according to emp Delete the department number in the table dept In the information
-- Implicit cursors
begin
delete from dept where deptno in(select distinct deptno from emp);
end;
-- Batch binding
declare
-- Declare nested table types
type a is table of dept.deptno%type;
-- Declare variables that host nested table types
b a;
-- Declare variables
c dept.deptno%type;
begin
-- assignment
SELECT DISTINCT DEPTNO BULK collect INTO b FROM EMP;
-- Batch binding
forall i in b.first..b.last
delete from DEPT where deptno=b(i);
end;
边栏推荐
- Flutter WebView jitter
- 基于C语言的哈夫曼转化软件
- PXE principles and concepts
- [recommended collection] MySQL 30000 word essence summary index (II) [easy to understand]
- Dear teachers, how can sqlserver get DDL in flinkcdc?
- Study notes of automatic control principle --- stability analysis of control system
- Maximum common substring & regularity problem
- P1825 [USACO11OPEN]Corn Maze S
- Kept dual machine hot standby
- 【FreeSwitch开发实践】使用SIP客户端Yate连接FreeSwitch进行VoIP通话
猜你喜欢
SSH,NFS,FTP
File management file system based on C #
Mycat2 sub database and sub table
Huffman transformation software based on C language
Study notes of automatic control principle --- stability analysis of control system
[untitled]
Memory management based on C language - Simulation of dynamic partition allocation
pl/sql之动态sql与异常
内存管理-动态分区分配方式模拟
PXE principles and concepts
随机推荐
Kept dual machine hot standby
基于C语言设计的换乘指南打印系统
Neo eco technology monthly | help developers play smart contracts
Flutter text is left aligned with no blank space in the middle
Flutter WebView jitter
Alphabetic string
The full name of flitter IDFA is identity for advertisers, that is, advertising identifiers. It is used to mark users. At present, it is most widely used for advertising, personalized recommendation,
海内外媒体宣发自媒体发稿要严格把握内容关
为什么要在时钟输出上预留电容的工位?
Ansible important components (playbook)
解决C#跨线程调用窗体控件的问题
Hegong sky team vision training Day6 - traditional vision, image processing
Flutter compilation fails
12306 ticket system crawling - 1. Saving and reading of city code data
When developing flutter, idea_ ID cannot solve the problem
Using the primitive root of module m to judge and solve
uni-app 简易商城制作
Pxe原理和概念
Study notes of automatic control principle -- dynamic model of feedback control system
Dear teachers, how can sqlserver get DDL in flinkcdc?