mysql json存null字符串怎么查?

mysql json存null字符串怎么查?

如图, sport 是 json 字段,要把sport为 null 字符串这一行查出来

无效查询

select * from tb where sport = 'null'
select * from tb where sport is null
SELECT * FROM tb WHERE sport = '"null"'

MySQL5.7 的 json 字符串

能存 json字符串, null字符串, null值, 数字
但是不能存其它 纯字符串

本作品采用《CC 协议》,转载必须注明作者和本文链接
reading
白小二
《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
讨论数量: 10

用双引号包起来

select * from tb where json_str = '"null"'
2年前 评论
白小二 (楼主) 2年前
Rache1 (作者) 2年前
seaChild

select * from 24ke_work_task where json =json_array() or json is null 如果是json 里面的字段 要这样 json->'$.field' = json_array()

file

2年前 评论
白小二 (楼主) 2年前
select * from tb where JSON_CONTAINS(`sport`, 'null');
select * from tb where JSON_CONTAINS(`sport`, 'null', '$');
2年前 评论

SELECT * FROM tb WHERE JSON_TYPE(sport) = 'NULL'

2年前 评论

select * from tb where JSON_TYPE(sport) is NULL

2年前 评论

select * from tb where JSON_DEPTH(sport) = 1

2年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!