查询语句的怪问题,大家帮忙解释一下

precipitant 2005-08-03 05:12:38
我查询一个数据表,想将某列既不是null也不是空格的行查出来。可是不行:
例如:select old_dept,remark,dept_code,dept_name from cst_dept_syn where 1=1 and dept_name is not null and dept_name!=''
就啥也查不出来了。
如果我这样就能查出来, select old_dept,remark,dept_code,dept_name from cst_dept_syn where 1=1 and dept_name is not null and dept_name || ' '!=' '



真的不知道oracle是如何看待空字符串的。大家帮忙分析一下。
...全文
96 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
precipitant 2005-08-08
  • 打赏
  • 举报
回复
但是如果用 is null 就将所有 null的查出来 而 =' '则只能将 值为 ' '的查出来。
而如果随便一个 !='liu'什么的 null的也被忽略掉。如果想把所有 不等于 'liu' 的全查出来包括 null的,就需要:
a!='liu' or a is null
precipitant 2005-08-04
  • 打赏
  • 举报
回复
明白了。

oracle的确把0长度字符串和null等同处理。

如果一个列有0长度字符串或者null,我们要过滤掉

好像 is not null 时 自动将null 和 0长度字符串过滤掉。
而!=' ' 时 自动将null 和 0长度字符串和1长度字符串过滤掉。

而 如果用 ='' 或者 !=''那么什么都查不出来。

laofang 2005-08-03
  • 打赏
  • 举报
回复
空格是' '而不是''

select old_dept,remark,dept_code,dept_name from cst_dept_syn
where 1=1 and dept_name is not null and dept_name != ' '
这样难道会查不出?
waterfirer 2005-08-03
  • 打赏
  • 举报
回复
把and dept_name!=''去掉就行了
UandM 2005-08-03
  • 打赏
  • 举报
回复
oracle中''就是null
查询的时候就是is null和is not null

17,140

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧