gpt4 book ai didi

mysql - 在纯 MySQL 中从 JSON 字符串获取值

转载 作者:行者123 更新时间:2023-11-29 10:27:54 25 4
gpt4 key购买 nike

我正在寻找一个纯MySQL单一查询。此查询的目标是利用诸如 SUBSTRING_INDEX 之类的内容。 , CONCAT ,或者任何需要的东西,以便在字符串中查找值。

假设该字符串看起来像这样: {"name":34,"otherName":55,"moreNames":12,"target":26,"hello":56,"hi":26,"asd":552,"p":3722,"bestName":11,"cc":6,"dd":10,}

我的目标是获得 target 的值,在这种情况下,26 。然而,"target":26可能并不总是位于字符串中的该位置。其他任何属性也不会。最重要的是,该值可能并不总是 26 。我需要某种方法来检查 "target": 之后的数字但在,之前之后"target": 。有什么办法可以做到这一点吗?

最佳答案

这个?

create table sandbox (id integer, jsoncolumn varchar(255));
insert into sandbox values (1,'{"name":34,"otherName":55,"moreNames":12,"target":26,"hello":56,"hi":26,"asd":552,"p":3722,"bestName":11,"cc":6,"dd":10}');

mysql root@localhost:sandbox> SELECT jsoncolumn->'$.target' from sandbox;
+--------------------------+
| jsoncolumn->'$.target' |
|--------------------------|
| 26 |
+--------------------------+

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

关于mysql - 在纯 MySQL 中从 JSON 字符串获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47944299/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com