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. CF 1172E Nauuo and ODT ——LCT

    题目:http://codeforces.com/contest/1172/problem/E LCT好题. 考虑对每个颜色求出 “不是该颜色的点组成的连通块的 siz2 之和” .每个颜色用 LCT ...

  2. 2-prometheus各组件安装

    相关下载: https://prometheus.io/download/https://github.com/prometheus/ 相关文档 https://songjiayang.gitbook ...

  3. GameObject.Find

    代码演示: using System.Collections;using System.Collections.Generic;using UnityEngine; public class Game ...

  4. 使用nsenter进入docker容器后端报错 mesg: ttyname failed: No such file or directory

    通过nsenter 进入到docker容器的后端总是报下面的错,, [root@devdtt ~]# docker inspect -f {{.State.Pid}} mynginx411950 [r ...

  5. jenkins配置到gitlab拉代码

    参照: jenkins 从git拉取代码-简明扼要 https://www.cnblogs.com/jwentest/p/7065783.html 持续集成①安装部署jenkins从git获取代码-超 ...

  6. 测开之路二十八:Flask基础之静态资源

    Flask默认的存放静态资源的目录名为static 在工程下创建一个文件夹(与脚本同级) 如果想命名为其他名字,则在声明app的时候要初始化,如: 准备一张图片放在static下,返回的内容加上img ...

  7. RQNOJ PID331 家族

    题目描述 若某个家族人员过于庞大,要判断两个是否是亲戚,确实还很不容易,现在给出某个亲戚关系图,求任意给出的两个人是否具有亲戚关系. 规定:x和y是亲戚,y和z是亲戚,那么x和z也是亲戚.如果x,y是 ...

  8. css深入理解overflow

    1.基本属性 visible(默认值) 超出部分仍然正常显示 hidden 超出后隐藏 scroll 滚动条一致显示 auto 自适应 显示或隐藏滚动条 inherit overflow  =  ov ...

  9. luoguP1314 聪明的质监员 题解(NOIP2011)

    P1314 聪明的质监员 题目 #include<iostream> #include<cstdlib> #include<cstdio> #include< ...

  10. js中获取input中所输入的值

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...