mysql8.0 JSON_CONTAINS使用方法
语法:JSON_CONTAINS(json_doc, val[, path])案例:select * from tbwhere info->'$.name' = '特价促销' or JSON_CONTAINS(info->'$[*].name', '"特价促销"', '$')SET @json = '{"A": 0, "B": {"C": 1}, ...
·
语法:
JSON_CONTAINS(json_doc, val[, path])
案例:
select * from tb
where info->'$.name' = '特价促销' or JSON_CONTAINS(info->'$[*].name', '"特价促销"', '$')
SET @json = '{"A": 0, "B": {"C": 1}, "D": 2}';
SELECT JSON_CONTAINS(@json, '2', '$.A');
+----------------------------------+
| JSON_CONTAINS(@json, '2', '$.A') |
+----------------------------------+
| 0 |
+----------------------------------+
SELECT JSON_CONTAINS(@json, '2', '$.D');
+----------------------------------+
| JSON_CONTAINS(@json, '2', '$.D') |
+----------------------------------+
| 1 |
+----------------------------------+
SELECT JSON_CONTAINS(@json, '{"C": 1}', '$.A');
+-----------------------------------------+
| JSON_CONTAINS(@json, '{"C": 1}', '$.A') |
+-----------------------------------------+
| 0 |
+-----------------------------------------+
SELECT JSON_CONTAINS(@json, '{"C": 1}', '$.B');
+-----------------------------------------+
| JSON_CONTAINS(@json, '{"C": 1}', '$.B') |
+-----------------------------------------+
| 1 |
+-----------------------------------------+
更多推荐
已为社区贡献2条内容
所有评论(0)