• 查询不为空的字段


    数据📊

    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
  • 相关阅读:
    map的使用方法
    APP的UI自动化demo(appium+java)
    总结Kibana DevTools如何操作elasticsearch的常用语句
    『现学现忘』Git基础 — 13、Git的基础操作
    JavaWeb_第5章_JSP
    超详细DeepLabv3 介绍与使用指南 – 使用 PyTorch 推理
    1086 就不告诉你
    基于SSM的概念可视化程序设计学习系统毕业设计源码021009
    数据仓库架构详解
    open62541开发:添加sqlite3 历史数据库
  • 原文地址:https://blog.csdn.net/lln1540295459/article/details/127917431