如何使用not in子句获取oracle结果,如果过滤键有值,则记录应根据过滤键过滤,如果过滤键值为null则使用相同的查询获取所有行?
select * from master_curtomers
where cus_index not in (pid);
答案 0 :(得分:2)
不完全确定你在问什么,但这是一种非常常见的模式:
select *
from table
where (id=p_id or p_id is null)
答案 1 :(得分:1)
你可以简单地使用or或
where ((pid is not null and cus_index not in (pid))
or pid is null)
我认为可以简化为
where (cus_index not in (pid) or pid is null)
因为NOT IN (NULL)
将不返回任何行