[英]Query is working in sql developer but not in sql plus and it should throw an error
select *
from emp
where
(select salary from dual) in (select salary from employees);
EMP
table has the same 107 which are in table EMPLOYEES
. EMP
表具有与表EMPLOYEES
中相同的 107。 Here select salary from dual
should produce an error in the where clause but it does not.在这里
select salary from dual
应该在 where 子句中产生错误,但它不会。 How?如何?
On the other hand it is returning rows in SQL Developer, but not in sqlplus.另一方面,它返回 SQL Developer 中的行,但不在 sqlplus 中。 Why?
为什么?
Good, Hopefully, it'll teach you to use table aliases .很好,希望它能教您使用表别名。 Without them, it was a column from the
emp
table;没有它们,它是
emp
表中的一列; as it exist, no error was thrown.因为它存在,所以没有引发错误。
I don't have your tables so Scott's will do.我没有你的桌子,所以斯科特会做。
SQL> create table employees as select * From emp where deptno = 10;
Table created.
SQL> select a.*
2 from emp a
3 where
4 (select a.sal from dual d) in (select b.sal from employees b);
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- -------- ---------- ---------- ----------
7782 CLARK MANAGER 7839 09.06.81 2450 10
7839 KING PRESIDENT 17.11.81 5000 10
7934 MILLER CLERK 7782 23.01.82 1300 10
SQL> select a.*
2 from emp a
3 where
4 (select d.sal from dual d) in (select b.sal from employees b);
(select d.sal from dual d) in (select b.sal from employees b)
*
ERROR at line 4:
ORA-00904: "D"."SAL": invalid identifier
SQL>
Why are you using a subquery when it is not necessary?为什么在不需要时使用子查询? This should do what you want:
这应该做你想要的:
select e.*
from emp e
where e.salary in (select salary from employees);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.