sql - ORACLE中如何从JSON中提取嵌套节点值
问题描述
我正在尝试从 Json 下方提取嵌套节点(以 CLOB 格式存储在名为 DOC 的列中),但它是空白的。
{
"id": "a3ac3bec-4c4e-42c8-a11c-068f3dfda201",
"createdDateTime": "2021-08-31T18:00:44Z",
"userDisplayName": "abc",
"userPrincipalName": "sad2547@gmail.com",
"userId": "36a3a1f2-6133-4a0b-a6c9-020693ebdbd3",
"appId": "1fa516bf-1332-4140-85c9-d844d4e69ca1",
"appDisplayName": "ProxyIdentityExperienceFramework",
"ipAddress": "999.99.0.999",
"clientAppUsed": "Mobile Apps and Desktop clients",
"correlationId": "c478bdd4-1541-4cd0-bf7e-bd0695325246",
"conditionalAccessStatus": "notApplied",
"isInteractive": true,
"riskDetail": "hidden",
"riskLevelAggregated": "hidden",
"riskLevelDuringSignIn": "hidden",
"riskState": "none",
"riskEventTypes": [],
"riskEventTypes_v2": [],
"resourceDisplayName": "IdentityExperienceFramework",
"resourceId": "a3c649c7-5daa-4c3f-a5a0-a3fd7281ee20",
"status": {
"errorCode": 0,
"failureReason": "Other.",
"additionalDetails": null
},
"deviceDetail": {
"deviceId": "",
"displayName": "",
"operatingSystem": "Windows 10",
"browser": "Chrome 92.0.4515",
"isCompliant": false,
"isManaged": false,
"trustType": ""
},
"location": {
"city": "xyz",
"state": "def",
"countryOrRegion": "US",
"geoCoordinates": {
"altitude": null,
"latitude": 12.65875,
"longitude": -74.65286
}
},
"appliedConditionalAccessPolicies": []
}
以下是我的查询:
SELECT x.*
FROM demo_json a,
JSON_TABLE(doc, '$'
COLUMNS (
ids VARCHAR2(100) PATH '$.id',
NESTED PATH '$.deviceDetail.*' COLUMNS
(
browser VARCHAR2(100) PATH '$.browser'
)
)
) x;
从 json 中检索所有嵌套节点的任何建议?
谢谢
解决方案
您的 JSON 在 userPrincipalName 中包含错误(缺少双引号):"userPrincipalName": sad2547@gmail.com,
应该是"userPrincipalName": "sad2547@gmail.com",
如果你修复它,它工作正常:
https://dbfiddle.uk/?rdbms=oracle_18&fiddle=d340a38b993f78170e04750e2aa8013c
with DEMO_JSON (doc) as (
select q'[
{
"id": "a3ac3bec-4c4e-42c8-a11c-068f3dfda201",
"createdDateTime": "2021-08-31T18:00:44Z",
"userDisplayName": "abc",
"userPrincipalName": "sad2547@gmail.com",
"userId": "36a3a1f2-6133-4a0b-a6c9-020693ebdbd3",
"appId": "1fa516bf-1332-4140-85c9-d844d4e69ca1",
"appDisplayName": "ProxyIdentityExperienceFramework",
"ipAddress": "999.99.0.999",
"clientAppUsed": "Mobile Apps and Desktop clients",
"correlationId": "c478bdd4-1541-4cd0-bf7e-bd0695325246",
"conditionalAccessStatus": "notApplied",
"isInteractive": true,
"riskDetail": "hidden",
"riskLevelAggregated": "hidden",
"riskLevelDuringSignIn": "hidden",
"riskState": "none",
"riskEventTypes": [],
"riskEventTypes_v2": [],
"resourceDisplayName": "IdentityExperienceFramework",
"resourceId": "a3c649c7-5daa-4c3f-a5a0-a3fd7281ee20",
"status": {
"errorCode": 0,
"failureReason": "Other.",
"additionalDetails": null
},
"deviceDetail": {
"deviceId": "",
"displayName": "",
"operatingSystem": "Windows 10",
"browser": "Chrome 92.0.4515",
"isCompliant": false,
"isManaged": false,
"trustType": ""
},
"location": {
"city": "xyz",
"state": "def",
"countryOrRegion": "US",
"geoCoordinates": {
"altitude": null,
"latitude": 12.65875,
"longitude": -74.65286
}
},
"appliedConditionalAccessPolicies": []
}]' doc from dual
)
SELECT
x.*
FROM DEMO_JSON a,
JSON_TABLE(a.DOC, '$'
COLUMNS (
IDs VARCHAR2(100) PATH id,
nested path deviceDetail columns(
browser path browser
)
)
) X;
推荐阅读
- lucene - 在 Lucene 中高效地执行批量精确匹配查找?
- html - 如何为 html 网站上的文本添加对比度?
- java - 如何在不阻塞的情况下从 Spring Webflux 中的 Mono 对象中提取数据?
- ios - React Native 图像未在较新版本的 iOS 上呈现
- excel - 使用超过 2 个 IF 条件来识别混合列中的不同数据类型 - Power Query
- jquery - Ruby on rails + jquery - 如何使用
- c++ - 交叉编译基于 proto 的库 c++ 的风险
- angular10 - Angular 10:找不到模块:错误:无法解析“ng2-date-picker/date-picker.module”
- javascript - 如何查找和删除两个不同数组中匹配的元素?Javascript
- bash - 在 skaffold 部署期间提取 pod 日志