gpt4 book ai didi

mysql - 获取 mysql 中 JSON 数组元素的索引

转载 作者:行者123 更新时间:2023-12-02 00:47:39 30 4
gpt4 key购买 nike

我有一个 JSON 数字数组,例如 [16, 9, 11, 22, 23, 12]。我想获取数组中数字的索引。例如我说我想要索引为9,它应该返回1。

我尝试在 MySQL 中使用下面提到的查询,但得到 null。

SELECT JSON_SEARCH(CAST('[16, 9, 11, 22, 23, 12]' AS JSON),'one',9)

你们有解决办法吗?

最佳答案

此处不需要

CAST。但数组值应该用引号引起来

JSON_SEARCH(json_doc, one_or_all, search_str[, escape_char[, path] ...])

Returns the path to the given string within a JSON document.

SELECT json_search('["16", "9", "11", "22", "23", "12"]', 'one', '9');

返回“$[1]”

关于mysql - 获取 mysql 中 JSON 数组元素的索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48723877/

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