mysql5.7中 json函数

官方文档:json相关函数

https://dev.mysql.com/doc/refman/5.7/en/json-creation-functions.html

https://dev.mysql.com/doc/refman/5.7/en/json-attribute-functions.html#function_json-type

 

json数组,数组元素是对象

# 表字段名:  templates
# json内容: [{"expression": "true", "id": 2}]

SELECT * FROM t_rule WHERE json_contains(templates, json_object('id', 1)) ; SELECT * FROM t_rule WHERE json_contains(templates, json_object('expression', 'true')) ;

 

select use_devices->'$[*].templates' from t_rule where json_contains(use_devices->'$[*].templates','["true"]');

 

SELECT count(*) FROM tb_cust_order WHERE tenant_code='shibei' and old_meters->'$[0].oldMeterOtherPics' <> '' 

 

访问数组下标     :  $[0]
通过key取value  :  $key.value

复制代码
json_extract : 取出来的value是带引号的
SELECT json_extract(表字段,'$key') title FROM tableName LIMIT 1

$key-> : 取出来的value是带引号的

SELECT 表字段->'$key' title FROM tableName LIMIT 1

$key->> : 取出来的value是不带引号的

SELECT 表字段->'$key' title FROM tableName LIMIT 1

json_unquote : 取出来的value是不带引号的

SELECT json_unquote(表字段->'$key') title FROM tableName LIMIT 1
————————————————
版权声明:本文为CSDN博主「小安青山」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_31775377/article/details/113858777
复制代码

 

 

 

https://blog.csdn.net/zijikanwa/article/details/113002152

posted @   Peter.Jones  阅读(169)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 在鹅厂做java开发是什么体验
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
历史上的今天:
2021-03-05 通过jdbc获取MySQL元数据
2021-03-05 定时任务表达式cron
点击右上角即可分享
微信分享提示