gpt4 book ai didi

json - 如何从 Oracle JSON 列获取数组索引?

转载 作者:行者123 更新时间:2023-12-05 09:16:55 25 4
gpt4 key购买 nike

有这样的 JSON(我知道 JSON 不支持注释。在这种情况下用于说明这个想法):

{
"people": [
{ --// <-- index 0
"id": 100,
"name": "John Doe"
},
{ --// <-- index 1
"id": 101,
"name": "Jane Roe"
}
]
}

我们可以像这样从数组中的特定元素中选择值:

SELECT name
FROM JSON_TABLE(
'{
"people": [
{
"id": 100,
"name": "John Doe"
},
{
"id": 101,
"name": "Jane Roe"
},
]
}', '$.people[*]'
COLUMNS(
ID NUMBER PATH '$.id',
NAME VARCHAR2 PATH '$.name'
)
) info
WHERE info.id = 101

结果:

NAME
--------
Jane Roe

有没有办法获取数组中的元素索引?像这样的东西:

SELECT array_index    --//  <-- how get the array index of the element found?
FROM JSON_TABLE(
--// ...
) info
WHERE info.id = 101

结果:

ARRAY_INDEX
-----------
1

是否可以使用 Oracle 12c 中的 JSON 支持来做这样的事情?

最佳答案

COLUMNS(
idx FOR ORDINALITY,
ID NUMBER PATH '$.id',
NAME VARCHAR2 PATH '$.name'
)

应该适合你

关于json - 如何从 Oracle JSON 列获取数组索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49438081/

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