select t.*, t.rowid from tb_onlinesetup t where sgkszy is null可以查到数据select t.*, t.rowid from tb_onlinesetup t where sgkszy=(case when sgkszy is not null then '普通员工' else null end) 查不到数据 不知错在哪里,请高手指教,谢谢
--没数据返回,是因为你没有 sgkszy 为 普通员工的数据create table tb_onlinesetup(sgkszy varchar2(20));insert into tb_onlinesetup select '普通员工' from dual union select '' from dual;---有数据返回 select t.*, t.rowid from tb_onlinesetup t where sgkszy=(case when sgkszy is not null then '普通员工' else null end);---如果仅查 普通员工的数据 select t.*, t.rowid from tb_onlinesetup t where sgkszy= '普通员工' ; ---如果查所有为null及普通的数据select t.*, t.rowid from tb_onlinesetup t where sgkszy= '普通员工' or t.sgkszy is null;---drop table tb_onlinesetup
select t.*, t.rowid from tb_onlinesetup t where sgkszy= '普通员工' or t.sgkszy is null
顺便讲一下,像这种,你可以考虑先用LENGTH看一下字段的长度!
楼上已经分析出错误了,注意 is null和 = null就好了
is null 和 =null 是两个概念~ 空和null不是相等的~ 查询前可以判断一下~
第一个SQL 检索了sgkszy为NULL的数据第二个SQL 检索了sgkszy为'普通员工'的数据很显然第二个写法明显有错,=NULL这样的写法是没有,什么数据都检索不出来。 你本意的是不是如6楼所写,要取出普通员工和NULL的数据。 (sgkszy= '普通员工' or sgkszy is null OR sgkszy = '') 所以,第二个SQL有检索到数据和第一个SQL没有检索到数据没有关系。
查询前可以判断一下~
select '普通员工' from dual
union select '' from dual;---有数据返回
select t.*, t.rowid from tb_onlinesetup t where
sgkszy=(case when sgkszy is not null then '普通员工' else null end);---如果仅查 普通员工的数据
select t.*, t.rowid from tb_onlinesetup t where
sgkszy= '普通员工' ;
---如果查所有为null及普通的数据select t.*, t.rowid from tb_onlinesetup t where
sgkszy= '普通员工' or t.sgkszy is null;---drop table tb_onlinesetup
sgkszy= '普通员工' or t.sgkszy is null
查询前可以判断一下~
第一个SQL
检索了sgkszy为NULL的数据第二个SQL
检索了sgkszy为'普通员工'的数据很显然第二个写法明显有错,=NULL这样的写法是没有,什么数据都检索不出来。
你本意的是不是如6楼所写,要取出普通员工和NULL的数据。
(sgkszy= '普通员工' or sgkszy is null OR sgkszy = '')
所以,第二个SQL有检索到数据和第一个SQL没有检索到数据没有关系。
那么你写的sql就不对了,因为null的比较不能用”=”号
所以你可以写个or条件就行了,没必要弄得这么复杂