我有下面的 JSON,我想读取discountDetail对象下的65300、230935、231832对象中的所有字段。问题是 65300、230935、231832 对象是动态的并且事先不知道。这些是在运行时创建的 id。有没有办法从 JSON 读取这样的动态嵌套对象?
{
"responseHeader": {
"transactionId": "357910e9558654b6:20f4dee6:18d59ad95c2:-800056572",
"status": {
"code": "SUCCESS",
"type": "S",
"description": "TRANSACTION SUCCESSFUL"
},
"discountDetail": {
"65300": {
"discountId": "65300",
"discountName": "Distributor Standard Discount - USD",
"discountDescription": "Standard - Distributor Standard Discount - USD",
"discountGroup": "Standard",
"modifierLineTypeCode": "DIS",
"discountMethodCode": "%",
"modifierNumber": "Distributor Standard Discount - USD",
"discountLineNumber": "Line, %",
"listHeaderId": "0.0",
"listLineId": "0.0",
"priceBreakTypeCode": "N",
"prorationTypeCode": "N",
"postTermClause": false,
"pricingPhaseId": "2",
"accrualIndicator": "N",
"automaticIndicator": "N",
"updateIndicator": "Y",
"appliedIndicator": "Y",
"overRideableIndicator": "Y"
},
"230935": {
"discountId": "230935",
"discountName": "BR-Deal Registration-USD",
"discountDescription": "Promotion-BR-Hunt-210731-10660",
"discountGroup": "Promotion",
"modifierLineTypeCode": "DIS",
"discountMethodCode": "%",
"modifierNumber": "BR-Deal Registration-USD",
"discountLineNumber": "Line,%",
"listHeaderId": "1566939",
"listLineId": "254610462",
"priceBreakTypeCode": "N",
"discountType": "ES",
"adjustmentMethodCode": "Additive",
"pricingPhaseId": "2.0",
"updateAllowableIndicator": "N",
"updateIndicator": "Y",
"appliedIndicator": "Y",
"printOnInvoiceIndicator": "N"
},
"231832": {
"discountId": "231832",
"discountName": "BR-Special Offers-USD",
"discountDescription": "Promotion-BR-MSSB-220730-12374",
"discountGroup": "Promotion",
"modifierLineTypeCode": "DIS",
"discountMethodCode": "%",
"modifierNumber": "BR-Special Offers-USD",
"discountLineNumber": "Line,%",
"listHeaderId": "561690",
"listLineId": "94777454",
"priceBreakTypeCode": "N",
"prorationTypeCode": "N",
"postTermClause": false,
"pricingPhaseId": "2",
"accrualIndicator": "N",
"automaticIndicator": "N",
"updateAllowableIndicator": "N",
"updateIndicator": "Y",
"appliedIndicator": "Y",
"printOnInvoiceIndicator": "N",
"overRideableIndicator": "N"
}
},
"qualifiedPromotions": {
"230935": {
"promotionId": "230935",
"promotionVersion": "25",
"promotionCode": "BR-Hunt-210731-10660",
"bundleType": "",
"channelProgramName": "Deal Registration",
"name": "Hunting",
"discType": "ES",
"autoApply": "N",
"promotionDiscountType": "Additive",
"startDate": "2022-12-21",
"endDate": "2023-06-04",
"status": "EXPIRED"
},
"231832": {
"promotionId": "231832",
"promotionVersion": "10",
"promotionCode": "BR-MSSB-220730-12374",
"bundleType": "ARCHITECTURE",
"channelProgramName": "Special Offers",
"name": "Meraki Smart Spaces Bundle - EEA",
"discType": "ES",
"startDate": "2023-02-10",
"endDate": "2023-07-29",
"status": "EXPIRED"
}
},
"disqualifiedPromotions": {
"233681": {
"promotionId": "233681",
"promotionCode": "PP-Fast-171028-02253",
"disqualifyReasons": [
{
"code": "D6102",
"message": "This promotion has expired."
}
]
}
},
"analyticalInfo": {
"REQUEST_PARSE_TIME": 0.442318,
"DC_CALL_TIME": 635,
"DC_TOTAL_TIME": 635,
"TOTAL_E2E_TIME": 1034,
"SAVM_TOTAL_TIME": 160,
"CR_PROCESS_TIME": 233,
"MDM_PROCESS_TIME": 47,
"PCV_INVOCATION_TIME": 118,
"BUNDLE_DISCOUNT_SERVICE_TIME": 153,
"LPS_CALL_TIME": 99,
"DEAL_DETAILS_LOG": 47,
"PGTMV_PROCESS_TIME": 26,
"CR_ES_INVOCATION_TIME": 232,
"GEC_SVC_CALL_TIME": 15,
"LPS_TOTAL_TIME": 100,
"PREPROCESS_TIME": 3
}
}
}
我想读取discountDetail对象下的65300、230935、231832动态嵌套对象中的所有字段。为什么它是动态的,因为这些是运行时生成的值?
JSON_TABLE 和 JSON_QUERY 都不支持 PATH 作为 SQL 表达式,因此您必须在 PL/SQL 中执行此操作才能使用动态 SQL。 此查询将为您提供“discountDetail”内容的所有路径,您可以从中构建返回实际内容的动态查询:
select p,
regexp_replace(p, '.*"([0-9]+)".*','\1') as id
from
json_table(
(select json_dataguide(js) from jsondata),
'$[*]'
columns (
p PATH '$."o:path"'
)
)
where to_number(regexp_replace(p, '.*"([0-9]+)".*','\1') default null on conversion error) is not null
;
$.responseHeader.discountDetail."65300" 65300
$.responseHeader.discountDetail."65300".discountId 65300
$.responseHeader.discountDetail."65300".listLineId 65300
$.responseHeader.discountDetail."65300".discountName 65300
$.responseHeader.discountDetail."65300".listHeaderId 65300
$.responseHeader.discountDetail."65300".discountGroup 65300
...
$.responseHeader.discountDetail."230935" 230935
$.responseHeader.discountDetail."230935".discountId 230935
$.responseHeader.discountDetail."230935".listLineId 230935
$.responseHeader.discountDetail."230935".discountName 230935
...