odp.net SQL查询从两个输入数组中检索行集
我有一个表,其主键由两列组成。我想基于两个输入数组检索一组行,每个数组对应一个主键列。
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设您想要两个表中任意位置都存在该键的所有行。
Assuming you want all rows where the key exists in both tables at any position.
这个问题现在已经解决了。如果您有兴趣,这就是答案。
http://forums.oracle.com/forums/thread。 jspa?threadID=1083982&tstart=15
This question is solved now. Here is the answer if you're interested.
http://forums.oracle.com/forums/thread.jspa?threadID=1083982&tstart=15