从Oracle执行的步骤来分析用IN的SQL与不用IN的SQL有以下区别: ORACLE试图将其转换成多个表的连接,如果转换不成功则先执行IN里面的子查询,再查询外层的表记录,如果转换成功则直接采用多个表的连接方式查询。 由此可见用IN的SQL至少多了一个转换的过程。一般的SQL都可以转换成功,但对于含有分组统计等方面的SQL就不能转换了。
一.SQL语言的使用1.IN 操作符 用IN写出来的SQL的优点是比较容易写及清晰易懂,这比较适合现代软件开发的风格。 但是用IN的SQL性能总是比较低的,从ORACLE执行的步骤来分析用
=null。 为什么都是or拼接,in可以而not in不可以呢,可以把not in理解为后面的and表达式就知道了,因为mgr=null为null,也就相当于false,导致整个表达式为false,无论传何值都为false,自然无法返回数据。 当发现not in后的子查询后面有null值时,可以在子查询里用is not null或函数过滤null值。 正如所看到的,not ...
statement does not return any rows. One of the values returned by the inner query is a null value and, therefore, the entire query returns no rows The reason is that all conditions that compare a null value result in a null. So whenever null values are likely to be part of the results...
therefore, the entire query returns no rows The reason is that all conditions that compare a null value result in a null. So whenever null values are likely to be part of the resultsset of a subquery, do not use the NOT INoperator. The NOT IN ...
SQL> selectempno,ename from emp where empno not in (select empno from emp1); EMPNO ENAME --- 8888 Dave 换成非null 字段就能正常显示了。 2.1 Null 说明 联机文档上的说明如下: http://download.oracle.com/docs/cd/E11882_01/server.112/e17118/sql_elements005.htm#i59110 A condition that eval...
Oracle Null 与 in, exists 的关系说明(not in 查不到结果),同事说查询遇到一个奇怪的事,2个表进行notin操作没有返回结果,正常情况下应该是有返回的。 一.问题重现一般来说,问题能重现就是好消息,最怕不能重现。 SQL>connscott/tiger;Connected.SQL>descemp Name
22、tances, it is better to use IN rather than EXISTS. In general, if the selective predicate is in the subquery, the n use IN. If the selective predicate is in the pare nt query, the n use EXISTS. Sometimes, Oracle can rewrite a subquery whe n used with an IN clause to take ad...
本文探讨了SQL中in、exists、not in、not exists子查询的使用及其差异,特别指出not in子查询在结果集含NULL值时可能导致空结果集。通过实验对比了不同子查询的执行结果和效率,建议在使用not in时去除NULL值以避免误差。
可以看出,not exists表示的关联子查询与 外连接方式表达的两条语句结果相同,而not in表示的非关联子查询的结果集为空。这是因为子查询select t2.c2 from t2查询结果含有NULL值导致的。NULL属于未知值,无法与其他值进行比较,无从判断,返回最终结果集为空。这一点在MySQL与Oracle中返回结果都是一致的。如果想表达最...