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 @ 2022-03-05 12:21  Peter.Jones  阅读(180)  评论(0)    收藏  举报