如何在oracle中查找与不同Rowid相似的数据?

问题描述:

我有这样一个表:如何在oracle中查找与不同Rowid相似的数据?

X Y 
====== 
20 20 
20 20 
20 21 
23 22 
22 23 
21 20 

我需要找到那些ROWID的地方X=Y但他们的ROWID是不一样的?像第一排的X和第二排的Y是一样的,但它们在不同的行中。

+1

''ROWID''在查询结果中两行不会相同 – mmuzahid

+0

您需要哪个'ROWID'值?在你的输出?例如,值'20'具有多个匹配的具有不同'ROWID'的记录对。你想要什么样的价值? –

+0

为什么你想要rowID? –

你可以做到这一点的方法很多,因为你所带来的rowid起来,这就是其中之一:

select * from yourtable tab1 join yourtable tab2 on tab1.x = tab2.y and tab1.rowid <> tab2.rowid 

你想重复行:

select * 
from 
(
    select x, y, rowid, count(*) over (partition by x,y) as cnt 
    from tab 
    where x=y 
) dt 
where cnt > 1 

请检查,如果这个工程

select * from tab a where exists (select * from tab b where a.x=b.y and a.rowid!=b.rownid); 
+0

这是对rownum 无效的user.table.column,table.column,或列规范 – 5A9U

+0

ROWNUM是从查询输出行时生成的伪列 - 它不是表中的列。也许你的意思是ROWID? –