create table

-- drop table tmp_20190706_220000
-- truncate table tmp_20190706_220000

create table tmp_20190706_220000 (
id integer,
name varchar(100),
memo varchar(200)
)
;

1
2
3
4
5
6
7
8
9
10
11
plsql into

通常简单的写法如下

declare
lv_id tmp_20190706_220000.id%type;
lv_name tmp_20190706_220000.name%type;
lv_memo tmp_20190706_220000.memo%type;

lv_sql varchar2(4000);
cur_tmp sys_refcursor;

begin
lv_sql:='select id,name,memo from tmp_20190704_220000 ';
open cur_tmp for lv_sql;
loop
fetch cur_tmp into lv_id,lv_name,lv_memo ;

exit when cur_tmp%notfound;

end loop;

close cur_tmp;

if cur_tmp%isopen then
close cur_tmp;
end if;

end;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
消耗时长

plsql bulk collect into

bulk collect 的写法如下

declare
type type_tmp_id is table of tmp_20190706_220000.id%TYPE index by pls_integer;
type type_tmp_name is table of tmp_20190706_220000.name%TYPE index by pls_integer;
type type_tmp_memo is table of tmp_20190706_220000.memo%TYPE index by pls_integer;

lv_id type_tmp_id;
lv_name type_tmp_name;
lv_memo type_tmp_memo;

lv_sql varchar2(4000);
cur_tmp sys_refcursor;

CN_BATCH_SIZE constant pls_integer :=100000;

begin
lv_sql:='select id,name,memo from tmp_20190704_220000 ';
open cur_tmp for lv_sql;
loop
fetch cur_tmp bulk collect into lv_id,lv_name,lv_memo limit CN_BATCH_SIZE;

exit when lv_id.count < CN_BATCH_SIZE;

end loop;

close cur_tmp;

if cur_tmp%isopen then
close cur_tmp;
end if;

end;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
消耗时长

差异还是蛮大的。

plsql into & insert into

declare
lv_id tmp_20190706_220000.id%type;
lv_name tmp_20190706_220000.name%type;
lv_memo tmp_20190706_220000.memo%type;

lv_sql varchar2(4000);
cur_tmp sys_refcursor;

begin
lv_sql:='select id,name,memo from tmp_20190704_220000 ';
open cur_tmp for lv_sql;
loop
fetch cur_tmp into lv_id,lv_name,lv_memo ;
insert into tmp_20190706_220000
( id,
name,
memo
)
values(
lv_id,
lv_name,
lv_memo
)
;
exit when cur_tmp%notfound;

end loop;

commit;
close cur_tmp;

if cur_tmp%isopen then
close cur_tmp;
end if;

end;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
消耗时长

plsql bulk collect into & insert into

declare
type type_tmp_id is table of tmp_20190706_220000.id%TYPE index by pls_integer;
type type_tmp_name is table of tmp_20190706_220000.name%TYPE index by pls_integer;
type type_tmp_memo is table of tmp_20190706_220000.memo%TYPE index by pls_integer;

lv_id type_tmp_id;
lv_name type_tmp_name;
lv_memo type_tmp_memo;

lv_sql varchar2(4000);
cur_tmp sys_refcursor;

CN_BATCH_SIZE constant pls_integer :=100000;

begin
lv_sql:='select id,name,memo from tmp_20190704_220000 ';
open cur_tmp for lv_sql;
loop
fetch cur_tmp bulk collect into lv_id,lv_name,lv_memo limit CN_BATCH_SIZE;
forall c_k in lv_id.FIRST .. lv_id.LAST
insert into tmp_20190706_220000(
id,
name,
memo
)
values (
lv_id(c_k),
lv_name(c_k),
lv_memo(c_k)
)
;
commit;

exit when lv_id.count < CN_BATCH_SIZE;

end loop;

close cur_tmp;

if cur_tmp%isopen then
close cur_tmp;
end if;

end;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
消耗时长

使用 bulk collect 和 forall 性能均有大幅度提高。
---------------------

oracle 批处理 bulk collect 带来的性能优势的更多相关文章

  1. Oracle forall bulk collect批量数据更新

    对于数据量较大的插入操作可采用此种方法操作,注意: limit减少内存占用,如果数据量较大一次性全部加载到内存中,对PGA来说压力太大,可采用limit的方法一次加载一定数量的数据,建议值通常为100 ...

  2. ORACLE fetch bulk collect into limit

    DECLARE TYPE rr IS REF CURSOR; TYPE r_emp IS RECORD( empno ), ename ), job ), mgr ), hiredate DATE, ...

  3. oracle中bulk collect into用法

    通过bulk collect减少loop处理的开销 采用bulk collect可以将查询结果一次性地加载到collections中. 而不是通过cursor一条一条地处理. 可以在select in ...

  4. PLSQL_性能优化系列11_Oracle Bulk Collect批处理

    2014-10-04 Created By BaoXinjian

  5. PL/SQL批处理语句(BULK COLLECT子句和FORALL语句)

    Oracle为PL/SQL中的SQL相关功能提供了FORALL语句和BULK COLLECT子句,显著的增强了SQL相关功能.这两个语句一起被称作PL/SQL的批处理语句.Oracle为什么要提供这两 ...

  6. bulk collect 在KingbaseES和Oracle的使用方法比较

    概述 BULK COLLECT 子句会批量检索结果,即一次性将结果集绑定到一个集合变量中,并从SQL引擎发送到PL/SQL引擎.通常可以在SELECT INTO.FETCH INTO以及RETURNI ...

  7. Oracle数据库之FORALL与BULK COLLECT语句

    Oracle数据库之FORALL与BULK COLLECT语句 我们再来看一下PL/SQL块的执行过程:当PL/SQL运行时引擎处理一块代码时,它使用PL/SQL引擎来执行过程化的代码,而将SQL语句 ...

  8. oracle学习之bulk collect用法

    通过bulk collect减少loop处理的开销,使用Bulk Collect提高Oracle查询效率 Oracle8i中首次引入了Bulk Collect特性,该特性可以让我们在PL/SQL中能使 ...

  9. ORACLE PL/SQL开发--bulk collect的用法 .

    刚刚在inthirties老大的博客里看到这篇文章,写的不错,正好自己最近在学习PL/SQL,转过来学习学习. ============================================ ...

随机推荐

  1. C++ string.replace的使用

    //下面是一个检查一个字符串中是否有'.'的函数,该函数将找到的'.'转化为'_'. inline void checkName(string& name) { std::; while (s ...

  2. iOS 获取全局唯一标示符

    这个方法用来产生一个唯一的标示符,每次调用都会不一样,所以可以用当作一些临时缓存文件的名字 NSString *identifier = [[NSProcessInfo processInfo] gl ...

  3. JetBrains CLion

    JetBrains CLion 2017.2.4 ①.激活时选择License server: http://idea.irfen.me/ http://idea.imsxm.com/

  4. 嵌入式开发环境搭建(一) 虚拟机实现桥接Ethernet网口 并且通过WIFI进行NAT联网

    背景: 目前手头上有一块JZ2440的板子,之前有搭建完整套开发环境,由于虚拟机故障需要从新搭建服务器端,故在此记录搭建步骤 环境: Ubuntu16.4 VMWare 12 先行条件: 先按照自定义 ...

  5. About Intel® Processor Numbers

    http://www.intel.com/content/www/us/en/processors/processor-numbers.html About Intel® Processor Numb ...

  6. 2.2寸(14PIN)TFT液晶屏STM32 SPI 控制

    屏幕如图所示,共14个IO口(也可能只有13个),控制屏幕的有9个IO口 详细版介绍见:http://www.ciast.net/post/20151112.html 反面IO口图: 连接通过SPI方 ...

  7. 重新认识Maven

    PS:第一次接触maven大约是两年前吧,隐约记得之前都是人工寻找并下载很多jar,放在项目的lib中(表示太年轻,没有接触过Ant或者其他类似的工具,就不找别人写的比较了).懒人永远有着自己的小聪明 ...

  8. 循环神经网络(RNN)入门介绍

    循环神经⽹络是为更好地处理时序信息而设计的.它引⼊状态变量来存储过去的信息,并⽤其与当前的输⼊共同决定当前的输出.循环神经⽹络常⽤于处理序列数据,如⼀段⽂字或声⾳.购物或观影的顺序,甚⾄是图像中的⼀⾏ ...

  9. vue - blog开发学习5

    基本功能和后台联调 1.首页的所有博客 因为是前后台都是本地开发,所以前端vue需要设置proxy:修改/config/index.js中的这个proxyTable proxyTable: { '/a ...

  10. 深入Spring:自定义IOC

    前言 上一篇文章讲了如何自定义注解,注解的加载和使用,这篇讲一下Spring的IOC过程,并通过自定义注解来实现IOC. 自定义注解 还是先看一下个最简单的例子,源码同样放在了Github. 先定义自 ...