数据📊
| id | name | parent_id |
|---|---|---|
| 1 | 党组织 | 0 |
| 2 | 陕西党委 | 1 |
| 3 | 1 | |
| 4 | Null | 2 |
| 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和空字符串都判断,具体看自己需求)












![[附源码]SSM计算机毕业设计中小企业人事管理系统JAVA](https://img-blog.csdnimg.cn/373bb24f0ce947d09e71d6a478758390.png)
![[附源码]Python计算机毕业设计安庆师范大学校园互助平台](https://img-blog.csdnimg.cn/d9f9f2a12fe848ed80e961536c38fb5d.png)





