我是靠谱客的博主 坚定哈密瓜,这篇文章主要介绍查询不为空的字段数据????实验⁉️总结????,现在分享给大家,希望可以做个参考。

数据????

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和空字符串都判断,具体看自己需求)

最后

以上就是坚定哈密瓜最近收集整理的关于查询不为空的字段数据????实验⁉️总结????的全部内容,更多相关查询不为空内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(135)

评论列表共有 0 条评论

立即
投稿
返回
顶部