mysql json操作
2022-12-04 12:38 youxin 阅读(222) 评论(0) 收藏 举报
MySQL根据JSON字段的内容检索查询数据
使用 字段->'$.json属性' 进行查询条件
使用 json_extract 函数查询,json_extract(字段, "$.json属性")
根据json数组查询,用 JSON_CONTAINS(字段, JSON_OBJECT('json属性', "内容"))

json格式
处理方式:

select * from log where data->'$.id' = 142;
或
select data->'$.id' id,data->'$.name' name from log where data->'$.id' = 142;
2,json数组格式

select name from country where JSON_EXTRACT(name, '$[1]') LIKE '%国际%'
JSON_EXTRACT
解读:提取json的key的值,如有多个则以数组返回
用法:可以用来判断或提取值,后面可以加like或=等匹配词,跟在select后面则返回符合的json字段值,跟在where后面则返回作为条件判断
https://dev.mysql.com/doc/refman/5.7/en/json-search-functions.html#function_json-search
https://www.cnblogs.com/cheyunhua/p/15882089.html
浙公网安备 33010602011771号