在(('x','y')中解释Oracle SQL的语法('a','b')

时间:2017-07-25 02:35:04

标签: sql oracle oracle12c

在Oracle SQL中,不接受此语法,返回ORA-00920: invalid relational operator

  select name
      from employees
     where (emp_id, dept_id) in (1 , 100)
        or (emp_id, dept_id) in (2, 200)
     order by emp_id;

虽然这种语法似乎完全有效(注意双括号)

 select name
  from employees
 where (emp_id, dept_id) in ((1 , 100))
    or (emp_id, dept_id) in ((2, 200))
 order by emp_id;

你能解释一下原因吗?我在Oracle文档中没有找到任何对此语法的引用。

1 个答案:

答案 0 :(得分:2)

我想你想要:

select name
from employees
where (emp_id, dept_id) in ((1, 100), (2, 200))
order by emp_id;

问题是你在比较元组。元组需要用自己的括号括起来。