签到成功

知道了

CNDBA社区CNDBA社区

批量插入,更新,删除数据

2016-09-02 11:47 2315 0 原创 SQL 开发
作者: Expect-乐

--插入数据:

http://www.cndba.cn/Expect-le/article/129
http://www.cndba.cn/Expect-le/article/129http://www.cndba.cn/Expect-le/article/129

declare
  --定义cursor把数据全部读入内存中
  cursor cur is
   select t.pk_account_detail_id from Ecm_Member_Account_Details t;
  --自定义集合类型
  type rec is table of cur%rowtype;
  recs rec;
begin
  open cur;
  while (true) loop
    fetch cur bulk collect
      into recs limit 10000;--10000行执行一次游标读取操作
    --把数据逐条插入
    forall i in 1 .. recs.count
       Insert /*+parllel(t,4)*/ Into test_a
        Select * from test_b t Where t.pk_payrefu_id=Recs(i).pk_payrefu_id;
    commit;
    exit when cur%notfound;
  end loop;
  close cur;
end;

--更新操作

http://www.cndba.cn/Expect-le/article/129
http://www.cndba.cn/Expect-le/article/129

declare
      type rowid_list is table of Number index by binary_integer;
   --   i number;
      rowid_infos rowid_list;
      cursor c_rowids is select t.pk_account_detail_id from Ecm_Member_Account_Details t ;
  begin
      open c_rowids;
      loop
       fetch c_rowids bulk collect into rowid_infos limit 10000;
       Forall i in 1..rowid_infos.count
          Update /*+parllel(t,4)*/ Ecm_Member_Account_Details Tt Set Tt.Fk_Order_Class_Id = 1
              where tt.pk_account_detail_id=rowid_infos(i);
       commit;
       exit when rowid_infos.count<10000;
     end loop;
     close c_rowids;
  end;

--删除操作http://www.cndba.cn/Expect-le/article/129

declare
  --定义cursor把数据全部读入内存中
  cursor cur is
   select t.id from test_a t;
  --自定义集合类型
  type rec is table of cur%rowtype;
  recs rec;
begin
  open cur;
  while (true) loop
    fetch cur bulk collect
      into recs limit 10000;--10000行执行一次游标读取操作
    --把数据逐条插入
    forall i in 1 .. recs.count
       delete From Ecm_Order_Payrefus t Where t.pk_id=Recs(i).id;
    commit;
    exit when cur%notfound;
  end loop;
  close cur;
end;


http://www.cndba.cn/Expect-le/article/129http://www.cndba.cn/Expect-le/article/129

http://www.cndba.cn/Expect-le/article/129
http://www.cndba.cn/Expect-le/article/129

版权声明:本文为博主原创文章,未经博主允许不得转载。

用户评论
* 以下用户言论只代表其个人观点,不代表CNDBA社区的观点或立场
Expect-乐

Expect-乐

关注

Without the continuous bitter cold, there can be no fragrant plum blossom

  • 336
    原创
  • 6
    翻译
  • 100
    转载
  • 41
    评论
  • 访问:1378212次
  • 积分:1957
  • 等级:核心会员
  • 排名:第3名
精华文章
    最新问题
    查看更多+
    热门文章
      热门用户
      推荐用户
        Copyright © 2016 All Rights Reserved. Powered by CNDBA · 皖ICP备2022006297号-1·

        QQ交流群

        注册联系QQ