[英]Querying JSON data field from Oracle table
ORACLE:我的“TESTREPAIR”表中有一个字段,其中一列“DETAILS”存储以下 JSON。
{
"repairActions": [
{
"symptom": 524,
"defect": "Defective Component",
"action": "Reflow"
},
{
"symptom": 506,
"defect": "Cosmetic",
"action": "Repaired Component"
},
{
"symptom": 509,
"defect": "Defective Component",
"action": "Swapped"
}
]
}
我正在使用 SELECT 语句从上述 JSON 数据字段中查询症状。
像这样。
SELECT
r.details.repairactions.symptom[0],
r.details.repairactions.symptom[1],
r.details.repairactions.symptom[2]
FROM
testrepair r;
上面的查询返回 null。 我想要的输出是
symptom1: 524
symptom2: 506
symptom3: 509
您希望将数组索引放在正确的位置并使用与 JSON 大小写匹配的带引号的标识符:
SELECT r.details."repairActions"[0]."symptom" AS symptom1,
r.details."repairActions"[1]."symptom" AS symptom2,
r.details."repairActions"[2]."symptom" AS symptom3
FROM testrepair r;
其中,对于样本数据:
CREATE TABLE testrepair (details JSON);
INSERT INTO testrepair (details)
VALUES ('{
"repairActions": [
{
"symptom": 524,
"defect": "Defective Component",
"action": "Reflow"
},
{
"symptom": 506,
"defect": "Cosmetic",
"action": "Repaired Component"
},
{
"symptom": 509,
"defect": "Defective Component",
"action": "Swapped"
}
]
}');
输出:
症状1 症状2 症状 3 524 506 509
db<> 在这里摆弄
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.