• 查询不为空的字段


    数据📊

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

    实验⁉️

    查询int类型不为空的字段

    select * from org where parent_id <> ""
    
    • 1

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

    在这里插入图片描述

    select * from org where parent_id != ""
    
    • 1

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

    select * from org where !ISNULL(parent_id)
    
    • 1

    ✔️
    在这里插入图片描述

    查询int类型为空的字段

    select * from org where parent_id = ""
    
    • 1

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


    在这里插入图片描述

    select * from org where ISNULL(parent_id)
    
    • 1

    ✔️
    在这里插入图片描述

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

    select * from org where name <> ""
    
    • 1

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

    select * from org where name != ""
    
    • 1

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

    select * from org where !ISNULL(name)
    
    • 1

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

    查询varchar类型为空的字段

    select * from org where name = ""
    
    • 1

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

    select * from org where ISNULL(name)
    
    • 1

    ✔️这是查询到了为空的

    在这里插入图片描述

    总结🌎

    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和空字符串都判断,具体看自己需求)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
  • 相关阅读:
    Kafka KRaft模式探索
    python中如何画语谱图
    【iOS开发--Swift语法】gard 的具体使用
    信号:singal
    刷题知识点2
    @ApiModel 和 @ApiModelProperty
    final关键字、抽象类、接口
    一起看 I/O | Android 开发工具最新更新
    【LeetCode-389】找不同
    珈创生物上市再次失败:先后折戟科创板、创业板,郑从义为董事长
  • 原文地址:https://blog.csdn.net/lln1540295459/article/details/127917431