楼主你这个需求不是很明确。 不过建议你看看merge into。你的旧数据没有必要删,直接根据你的条件update即可。 merge into的例子: -------实例-------drop table a; drop table b; create table a(id number(1),name varchar2(10)); create table b(id number(1),name varchar2(10)); insert into a values(1,'2'); insert into b values(1,'1'); insert into b values(2,'2'); commit;merge into a using (select id,name from b ) c on(a.id=c.id ) when not matched then insert (a.id,a.name) values (c.id,c.name); merge into a using (select id,name from b ) c on(a.id=c.id ) when matched then update set a.name=c.name;merge into a using (select id,name from b ) c on(a.id=c.id ) when matched then update set a.name=c.name when not matched then insert (a.id,a.name) values (c.id,c.name); 作用:将表 b 数据 更新到 表a ,条件是a.id=b.id,如果a表中有该条件的数据就修改,没有该条件的数据就插入。如果你的数据量很大,此sql效率非常高。
可是一变成DELETE 就非常慢了
然后不 旧数据 Delete
了不可以??
不过建议你看看merge into。你的旧数据没有必要删,直接根据你的条件update即可。
merge into的例子:
-------实例-------drop table a;
drop table b;
create table a(id number(1),name varchar2(10));
create table b(id number(1),name varchar2(10));
insert into a values(1,'2');
insert into b values(1,'1');
insert into b values(2,'2');
commit;merge into a
using (select id,name from b ) c
on(a.id=c.id )
when not matched then insert (a.id,a.name) values (c.id,c.name);
merge into a
using (select id,name from b ) c
on(a.id=c.id )
when matched then update set a.name=c.name;merge into a
using (select id,name from b ) c
on(a.id=c.id )
when matched then update set a.name=c.name
when not matched then insert (a.id,a.name) values (c.id,c.name);
作用:将表 b 数据 更新到 表a ,条件是a.id=b.id,如果a表中有该条件的数据就修改,没有该条件的数据就插入。如果你的数据量很大,此sql效率非常高。
哦?那不就是想要merge into 么?