1

我有一个主键由两列组成的表。我想根据两个输入数组检索一组行,每个数组对应一个主键列。

select pkt1.id, pkt1.id2, ... from PrimaryKeyTable pkt1, table(:1) t1, table(:2) t2
where pkt1.id = t1.column_value and pkt1.id2 = t2.column_value

然后我将值与 odp.net 中的两个 int[] 绑定。

这将返回结果行的所有不同组合。因此,如果我期待 13 行,我会收到 169 行 (13*13)。问题是 t1 和 t2 中的每个值都应该链接。值 t1[4] 应该与 t2[4] 一起使用,而不是 t2 中的所有不同值。

使用 distinct 解决了我的问题,但我想知道我的方法是否错误。有人对如何以最佳方式解决此问题有任何指示吗?一种方法可能是使用 for 循环依次访问 t1 和 t2 中的每个索引,但我想知道什么会更有效。

编辑:实际上不同并不能解决我的问题,它只是根据我的输入值(t2 = 0 中的所有值)完成的

4

2 回答 2

0

假设您想要在两个表中的任何位置都存在键的所有行。

select pkt1.id, pkt1.id2, ... 
from PrimaryKeyTable pkt1
where pkt1.id in (select column_value from table(:1)) 
and pkt1.id2 in (select column_value from table(:2)) 
于 2010-06-09T12:49:56.327 回答
0

这个问题现在解决了。如果你有兴趣,这里是答案。

select id1, id2 from t, (select rownum rn1, a1.* from table(:1) a1) a1, (select rownum rn2, a2.* from table(:2) t2) t2 where (id1, id2) in ((a1.column_value, a2.column_value)) and rn1 = rn2

http://forums.oracle.com/forums/thread.jspa?threadID=1083982&tstart=15

于 2010-06-09T21:29:04.670 回答