oracle批量DML(bulk connect into & forall)

批量dml会用到这两个,主要原理是加速SQL执行速度,原理是利用内存运算和减少sql引擎和plsql引擎的交互

伪代码如下:
1.不利用游标限制单次引擎的交互


declare 
  --定义记录变量或者rowtype类型
  type rec is record(a varchar2(10),
                     b varchar2(8));
  --定义嵌套表或者关联数组
  type nest_table is table of rec;
  --定义嵌套表或者关联数组对象
  t_rec nest_table;


begin 
  select level,level+1 bulk connect into t_rec 
    from dual connect by level<=10000;


  Forall i in 1..t_rec.count
      update table table_name 
        set column_name= t_rec(i).a
        where column_name1= t_rec(i).b;


    commit;


end;
/

–游标写法

declare 
  --定义记录变量或者rowtype类型
  type rec is record(a varchar2(10),
                     b varchar2(8));
  --定义嵌套表或者关联数组
  type nest_table is table of rec;
  --定义嵌套表或者关联数组对象
  t_rec nest_table;


begin 
  cursor cur is select level,level+1  
    from dual connect by level<=10000;

   fetch cur bulk connect into t_rec limit 100;


  Fora
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值