查询不为空的字段

数据📊

idnameparent_id
1党组织0
2陕西党委1
31
4Null2
5渭南党委Null

实验⁉️

查询int类型不为空的字段

select * from org where parent_id <> ""

❌mybatis 中的 if判断会把整形中的 0 识别为false(空)

在这里插入图片描述

select * from org where parent_id != ""

❌mybatis 中的 if判断会把整形中的 0 识别为false(空)
在这里插入图片描述

select * from org where !ISNULL(parent_id)

✔️
在这里插入图片描述

查询int类型为空的字段

select * from org where parent_id = ""

mybatis 中的 if判断会把整形中的 0 识别为false(空)


在这里插入图片描述

select * from org where ISNULL(parent_id)

✔️
在这里插入图片描述

查询varchar类型不为空Null的字段

select * from org where name <> ""

❌把空字符串和Null都过滤掉了
在这里插入图片描述

select * from org where name != ""

❌把空字符串和Null都过滤掉了
在这里插入图片描述

select * from org where !ISNULL(name)

✔️3这个其实是一个空字符串,结果是查询到了不为空的
在这里插入图片描述

查询varchar类型为空的字段

select * from org where name = ""

❌这是查询到了为空字符串的
在这里插入图片描述

select * from org where ISNULL(name)

✔️这是查询到了为空的

在这里插入图片描述

总结🌎

int类型用 ! isNull,varchar用 ! = “”

查询int类型
	- 不为空 select * from org where !ISNULL(parent_id)
	- 为空 select * from org where ISNULL(parent_id)
查询varchar类型
	- 不为空 select * from org where !ISNULL(name)
	- 不为空字符串 select * from org where name <> ""select * from org where name != "" 
	- 为空 select * from org where ISNULL(name)
	- 为空字符串 select * from org where name = ""
(一般判断字符串是否为空就是null和空字符串都判断,具体看自己需求)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值