odp.net SQL查询从两个输入数组中检索行集

发布于 2024-09-05 02:57:03 字数 549 浏览 3 评论 0原文

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

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 中的所有不同值一起使用。

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

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

I have a table with a primary key consisting of two columns. I want to retrieve a set of rows based on two input arrays, each corresponding to one primary key column.

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

I then bind the values with two int[] in odp.net.

This returns all different combinations of my resulting rows. So if I am expecting 13 rows I receive 169 rows (13*13). The problem is that each value in t1 and t2 should be linked. Value t1[4] should be used with t2[4] and not all the different values in t2.

Using distinct solves my problem, but I'm wondering if my approach is wrong. Anyone have any pointers on how to solve this the best way? One way might be to use a for-loop accessing each index in t1 and t2 sequentially, but I wonder what will be more efficient.

Edit: actually distinct won't solve my problem, it just did it based on my input-values (all values in t2 = 0)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浮云落日 2024-09-12 02:57:03

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

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)) 

Assuming you want all rows where the key exists in both tables at any position.

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)) 
梦与时光遇 2024-09-12 02:57:03

这个问题现在已经解决了。如果您有兴趣,这就是答案。

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

This question is solved now. Here is the answer if you're interested.

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文