create table table_a(id number(5),name varchar2(10),score number(2));
insert into table_a values(1,'aa',10);
insert into table_a values(2,'bb',10);
insert into table_a values(3,'cc',10);
insert into table_a values(4,'dd',10);
create table table_b(id number(5) unique,name varchar2(10),score number(2),batch_id number(10));
insert into table_b values(1,'xx',90,1);
insert into table_b values(2,'yy',80,1);
insert into table_b values(3,'zz',60,2);
insert into table_b values(4,'mm',70,2);
commit;
create bitmap index idx_eyes1000 on table_b(batch_id) nologging tablespace users compute statistics;
exec dbms_stats.gather_table_stats(ownname=>user,tabname=>'table_b',cascade=>true);
alter table table_a add constraint pk_a primary key (id) using index tablespace users;
alter table table_b add constraint pk_b primary key (id) using index tablespace users;
declare
type t_type is table of number(10);
v_batch_id t_type;
begin
execute immediate 'select distinct t.batch_id from table_b t' bulk collect into v_batch_id;
if v_batch_id.count>0 then
for i in v_batch_id.first..v_batch_id.last loop
update (select /*+ ordered */
x.name source_name,x.score source_score,
y.name target_name,y.score target_score
from table_b x,table_a y
where x.batch_id=v_batch_id(i)
and x.id = y.id)
set target_name = source_name,
target_score = source_score;
commit;
end loop;
end if;
end;
/
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/94041/viewspace-978810/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/94041/viewspace-978810/