具有3个输出的Oracle SQL WHERE CASE IN语句

时间:2018-06-25 10:47:59

标签: sql oracle case

我有一小段代码,在前端有一个参数输入。

输入选项为是,否和所有等于:

yes = TRUE
no = FALSE
all = TRUE & FALSE

我的代码是:

SELECT c.ID, 
c.rep, 
c.cust
FROM mytable c 
WHERE '&input' IN (
CASE WHEN 'yes' THEN c.Acc = 'TRUE'
     WHEN 'no' THEN c.Acc = 'FALSE'
     WHEN 'all' THEN c.Acc IN ('TRUE', 'FALSE')
END)

但收到错误:

  

ORA-00920:无效的关系运算符

2 个答案:

答案 0 :(得分:1)

我想你想要

SELECT c.ID, c.rep, c.cust
FROM mytable c 
WHERE (c.Acc =  = &input OR &input = 'all')

答案 1 :(得分:1)

使用OR

SELECT c.ID, 
    c.rep, 
    c.cust
FROM mytable c 
WHERE (&input = 'yes' and c.Acc = 'TRUE') OR
      (&input = 'no' and c.Acc = 'FALSE') OR
      (&input = 'all' and c.Acc IN ('TRUE', 'FALSE'))