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
白小二
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
讨论数量: 10

用双引号包起来

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

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

file

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

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

4年前 评论

select * from tb where JSON_TYPE(sport) is NULL

4年前 评论

select * from tb where JSON_DEPTH(sport) = 1

4年前 评论

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