IN CLAUSE中的Oracle条件

时间:2014-02-27 14:14:56

标签: sql oracle oracle11g

您好我正在编写oracle查询以支持select in in子句我的查询就像这样

SELECT * FROM country
WHERE 
country_id in( IF('test' = 'test',(1,2,3),true) )

如果condition('test'='test')为true,那么它应该像

那样触发查询
SELECT * FROM country WHERE  country_id in(1,2,3)

否则它应该触发查询

 SELECT * FROM country WHERE  country_id in(true)

1 个答案:

答案 0 :(得分:1)

如果我理解你需要什么,你必须将它分成两个条件:

SELECT * 
  FROM country
  WHERE(('test'='test')AND(country_id IN (1,2,3)))
     OR(('test'<>'test')AND(country_id<>0))