多列IN子句 [英] Multi-column IN clause

查看:94
本文介绍了多列IN子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于如何执行多列IN子句的任何想法?请注意,比较集来自应用程序内存,而不是Oracle中的子查询.因此,例如,我有两个数组,即IDs()和Names(),并且我想得到这样的东西:

Any ideas on how to do a multi-column IN clause? Note that the comparison set is coming from application memory, not a subquery in Oracle. So, for example, I have two arrays, IDs() and Names(), and I want to get something like this:

SELECT * FROM MY_TABLE WHERE (ID, NAME) NOT IN (:IDs, :Names) 


我收到的最常见错误是无效的关系运算符".

开放其他建议.我想避免建立像
这样的丑陋查询


Most common error I''ve been getting is "invalid relational operator".

Open to other suggestions. I''d like to avoid building an ugly query like

SELECT * FROM MY_TABLE WHERE (ID, NAME) NOT IN ((ID1,Name1), (ID2,Name2), ...) 


甚至更糟,


or even worse,

SELECT * FROM MY_TABLE WHERE (ID || NAME) NOT IN (:IDNames) 

推荐答案

以前,您必须选择要进行整型/省略的ID,然后将其压入临时表,然后使用临时表ID过滤记录.

这里是示例代码
Previously you have to select ids which you want to neglet/omit then push that ids into temp table and then filter records using temp table ids

here sample code
DECLARE @TempTable TABLE (Ids int)

insert into @TempTable(Ids)
select StudentIdid from StudentTable where StudentId<10
  
select StudentId,StudentName from StudentTable where StudentId not in (select Ids from @TempTable)



我希望您能理解...



i hope you understand...


您可以使用动态视图
单击此处2
You can use dynamic views
click here2


这篇关于多列IN子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆