日期:2014-05-17 浏览次数:20857 次
select t.col2
from (select tb1.col as col1,tb2.col as col2,row_number()over(partition by tb2.col order by tb2.col)rn
from tb1,tb2
where tb1.col(+)=tb2.col)t
where t.col1 is null or (t.rn<>1);
create table T1(name VARCHAR2(50));
create table T2(name VARCHAR2(50));
insert into T2 (NAME) values ('aaa');
insert into T2 (NAME) values ('bbb');
insert into T2 (NAME) values ('ddd');
insert into T2 (NAME) values ('ddd');
insert into T2 (NAME) values ('eee');
insert into T2 (NAME) values ('eee');
insert into T2 (NAME) values ('aaa');
insert into T2 (NAME) values ('bbb');
insert into T2 (NAME) values ('ccc');
insert into T2 (NAME) values ('aaa');
insert into T1 (NAME)values ('aaa');
insert into T1 (NAME)values ('bbb');
insert into T1 (NAME)values ('ccc');
insert into T1 (NAME)values ('ddd');
commit;
select row_number() over(partition by name order by name) rn, t2.*
from t2
minus
select row_number() over(partition by name order by name) rn, t1.*
from t1;