Oracle批量更新

①导出批量更新SQL

select CONCAT(CONCAT(CONCAT(CONCAT('update test_a set a_date=', b_date),
                            'where a_id='),
                     b_id),
              ' and a_flag=1;')
  from test_b;

②批量更新数据

#方法一  
update test_a a
   set a.a_date = (select b.b_date
                     from test_b b
                    where a.a_id = b.b_id
                      and a.a_flag = 1);
 
#方法二
begin
  for r in (select a.rowid, b.b_date
              from TEST_A a, test_b b
             where a.a_id = b.b_id
             and a.a_flag =1) loop
    update TEST_A t set t.a_date = r.b_date where t.rowid = r.rowid;
  end loop;
end;


#方法三
create or replace procedure test as
  type temp_record IS record(b_id test_b.b_id%type,
  b_date test_b.b_date%type
  );
  type temp_record_table IS table OF temp_record;
  tmp temp_record_table ;
begin
  SELECT b.b_id, b.b_date BULK COLLECT INTO tmp FROM test_b b;
  FOR I IN 1 .. tmp.COUNT LOOP
    UPDATE TEST_A a SET a.a_date = tmp(I).b_date
    WHERE a.a_id = tmp(I).b_id
         AND a.a_flag = 1;
  END LOOP;
end;


#方法四
merge into TEST_A a
using test_b b
on (a.a_id = b.b_id and a.a_flag = 1)
when matched then
  update set a.a_date = b.b_date;


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值