楼上写的有问题:如果 select Temp2.IsTrue from Temp2 where ID=Temp2.ID and rownum=1 没有返回值,则 set Temp1.IsTrue=NULL,会把原来的值更新成NULL;declare cursor cur_temp is select * from temp2; c_temp cue_temp%rowtype; begin open cur_tmep; loop fetch cur_temp into c_temp; exit when cur_tmep%notfound;
update temp1 set istrue=c_temp.istrue where id = c_tmep.id; end loop; close cur_temp; commit; exception when others then close cur_tmep; rollback; end;
如果记录数不多,可以这么写: UPDATE t1 SET value1=rec1.value1 WHERE d2_pk_id = rec1. d2_pk_id; 上述方法处理十万条以下的记录还是可以的,如果记录数不到1000万条,可以用循环,分批更新: UPDATE (SELECT t1.value1 a1, d2.value1 b1 FROM t1,d2 WHERE d2.d2_pk_id >= 10000000 and d2. d2_pk_id<10300000 And t1.d2_pk_id >= 10000000 and t1. d2_pk_id<10300000 And t1.d2_pk_id = d2.d2_pk_id ) SET a1 = b1;
如果记录数在1000万条以上,建立试用下列步骤: ⑴ 新建空表 Create table t2 as Select * from t1 where rownum < 1; ⑵把新建立的表置为NOLOGGING。 Alter table t2 nologging; ⑶插入数据。 Insert /*+ append */ into t2 a (col1,col2,col3,value1) Select b.col1,b.col2,b.col3,d2.value1 from t1 b, d2 Where b.d2_pk_id = d2. d2_pk_id ⑷t1是更新前的旧表,t2是更新后的新表。可把旧表改名或者删除,把新表改成需要的名字就可以了。
where ID=Temp2.ID and rownum=1
没有返回值,则
set Temp1.IsTrue=NULL,会把原来的值更新成NULL;declare
cursor cur_temp is select * from temp2;
c_temp cue_temp%rowtype;
begin
open cur_tmep;
loop
fetch cur_temp into c_temp;
exit when cur_tmep%notfound;
update temp1 set istrue=c_temp.istrue where
id = c_tmep.id;
end loop;
close cur_temp;
commit;
exception
when others then
close cur_tmep;
rollback;
end;
UPDATE t1
SET value1=rec1.value1
WHERE d2_pk_id = rec1. d2_pk_id;
上述方法处理十万条以下的记录还是可以的,如果记录数不到1000万条,可以用循环,分批更新:
UPDATE (SELECT t1.value1 a1, d2.value1 b1
FROM t1,d2
WHERE d2.d2_pk_id >= 10000000 and d2. d2_pk_id<10300000
And t1.d2_pk_id >= 10000000 and t1. d2_pk_id<10300000
And t1.d2_pk_id = d2.d2_pk_id )
SET a1 = b1;
⑴ 新建空表
Create table t2 as
Select * from t1 where rownum < 1;
⑵把新建立的表置为NOLOGGING。
Alter table t2 nologging;
⑶插入数据。
Insert /*+ append */ into t2 a
(col1,col2,col3,value1)
Select b.col1,b.col2,b.col3,d2.value1 from t1 b, d2
Where b.d2_pk_id = d2. d2_pk_id
⑷t1是更新前的旧表,t2是更新后的新表。可把旧表改名或者删除,把新表改成需要的名字就可以了。
以上仅供参考。