Oracle数据库批量fetch批量处理

Oracle数据库批量fetch批量处理

–第三种处理方式,批量fetch批量处理
declare
t1 NUMBER(20);
t2 NUMBER(20);
CN_BATCH_SIZE constant pls_integer := 1000;
type typ_empno is table of emp.empno%type index by binary_integer;
empnos typ_empno;
type typ_name is table of emp.ename%type index by binary_integer;
enames typ_name;
type typ_job is table of emp.job%type index by binary_integer;
jobs typ_job;
type typ_mgr is table of emp.mgr%type index by binary_integer;
mgrs typ_mgr;
type typ_hiredate is table of emp.hiredate%type index by binary_integer;
hiredates typ_hiredate;
type typ_sal is table of emp.sal%type index by binary_integer;
sals typ_sal;
type typ_comm is table of emp.comm%type index by binary_integer;
comms typ_comm;
type typ_deptno is table of emp.deptno%type index by binary_integer;
deptnos typ_deptno;
type typ_rid is table of urowid index by binary_integer;
rids typ_rid;

cur_emp sys_refcursor;
vc_sql varchar(4000) := ‘select empno,ename,job,mgr,hiredate,sal,comm,deptno,rowid from emp where empno> :1’;
begin
t1 := dbms_utility.get_time;
open cur_emp for vc_sql using 1;
loop
fetch cur_emp bulk collect into empnos,enames,jobs,mgrs,hiredates,sals,comms,deptnos,rids limit CN_BATCH_SIZE;
for i in 1 … rids.count loop
sals(i) := sals(i)+1;
end loop;
forall i in 1…rids.count
insert into emp_forall(empno,ename,job,mgr,hiredate,sal,comm,deptno)
values(empnos(i),enames(i),jobs(i),mgrs(i),hiredates(i),sals(i),comms(i),deptnos(i));
exit when rids.count < CN_BATCH_SIZE;
end loop;
close cur_emp;
commit;
t2 := dbms_utility.get_time;
dbms_output.put_line('FORALL: ’ || TO_CHAR(t2 - t1)/100);
end;
/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值