use*_*282 4 oracle null subquery notin
I have two tables: PROD and CUST On running the below query in SQL and SYBASE, it works. Oracle is not giving any results.
select * FROM PROD
where PROD.SECID NOT IN (SELECT CUST.SECID FROM CUST WHERE SECID <> '')
Run Code Online (Sandbox Code Playgroud)
NOTE: PROD.SECID has all null values. CUST.SECID has all non null values(valid values).
<>'' doesn't fetch any records from inner subquery so i changed it to IS NOT NULL and now it fetches the results.
但问题是,当查询作为一个整体运行时,它不会给出任何应有的结果。
NOT IN 正常工作。如果你有空值,你不能说它是“在”给定的集合中还是没有。
SQL> select case
2 when null in (1, 2, 3) then 'in'
3 when null not in (1, 2, 3) then 'not in'
4 else 'null'
5 end as result
6 from dual;
RESULT
------
null
Run Code Online (Sandbox Code Playgroud)
如果你想排除给定的值,你应该使用not exists,或者更好的是反连接:
select p.*
from prod p, cust c
where p.secid = c.secid (+)
and c.secid is null;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8089 次 |
| 最近记录: |