我从一个数据库中读数,往另外一个数据库中导入,每个表的数据量不同,最多有几百万条,因为我对oracle数据库的内存这方面不太了解,不知到如何写最好,请大家给点建议。
我现在有两种方法:
1、
truncate table a;insert into a
select * from b;有人说用truncate 比用delete不会产生垃圾空间,这个我不知道对不对,不过,要是有条件的话,就必须用delete拉。速度上,目前是90多万测过,大概几分钟,但是,导过10多万时,还出现10分钟导完,我不知道这个跟机器或者其他方面有关系吗?数据基本是每天导入一次,如果按上面的方法,全删在加,我不知道合不合理?大家说说看!2、删除原有已经修改得数据,这个有个字段可以判断,然后再添加原有数据没有的,这个有另一个字段判断。但是,执行效率上明显很慢,不知道是不是自己的sql语句写的有问题,具体如下:
delete from a
where not exists
(select * from
(select x1,x2 from x where x2 is not null)b
where (a.x1=b.x1 and a.x2=b.x2)
);insert into a
(select * from b
where not exists
(select * from a
where a.x1=b.x1));
请指点一下!
我现在有两种方法:
1、
truncate table a;insert into a
select * from b;有人说用truncate 比用delete不会产生垃圾空间,这个我不知道对不对,不过,要是有条件的话,就必须用delete拉。速度上,目前是90多万测过,大概几分钟,但是,导过10多万时,还出现10分钟导完,我不知道这个跟机器或者其他方面有关系吗?数据基本是每天导入一次,如果按上面的方法,全删在加,我不知道合不合理?大家说说看!2、删除原有已经修改得数据,这个有个字段可以判断,然后再添加原有数据没有的,这个有另一个字段判断。但是,执行效率上明显很慢,不知道是不是自己的sql语句写的有问题,具体如下:
delete from a
where not exists
(select * from
(select x1,x2 from x where x2 is not null)b
where (a.x1=b.x1 and a.x2=b.x2)
);insert into a
(select * from b
where not exists
(select * from a
where a.x1=b.x1));
请指点一下!
where 的时候,能过滤掉记录最多的条件放最右边,oracle的解析顺序
尽量select的时候不用*号
如果删除的是绝大多数据,建议把不删除的挑出来放到过渡表,然后把所有数据truncate,再把保存的的数据insert回来;再做你要insert的其它数据。
如果删除的是极少的数据,建议把not exits改成delete from a where rowid in(select a.rowid from a, b where a.x1=b.x1(+) and a.x2=b.x2(+) and (b.x1 is null or b.x2 is null)),思路是这样的具体要调试一下看看是否写的对。inert into修改方法类似.