I have a following JSON data in a CLOB variable. Let's call it as "p_clob".
{
"CustomerTransactionId": 300000164734650,
"DueDate": "2023-07-31",
"ConversionDate": null,
"ConversionRate": null,
"receivablesInvoiceLines": [
{
"LineNumber": 1,
"Description": "TEST DESCRIPTION1",
"Quantity": 10,
"UnitSellingPrice": 1100,
"TaxClassificationCode": null,
"SalesOrder": null
},
{
"LineNumber": 2,
"Description": "TEST DESCRIPTION2",
"Quantity": 10,
"UnitSellingPrice": 1100,
"TaxClassificationCode": null,
"SalesOrder": null
},
{
"LineNumber": 3,
"Description": "TEST DESCRIPTION3",
"Quantity": 10,
"UnitSellingPrice": 1100,
"TaxClassificationCode": null,
"SalesOrder": null
},
{
"LineNumber": 4,
"Description": "TEST DESCRIPTION4",
"Quantity": 10,
"UnitSellingPrice": 1100,
"TaxClassificationCode": null,
"SalesOrder": null
}
]
}
The array "receivablesInvoiceLines" has 4 lines.
I need to insert total of 4 rows in a table using a select below.
INSERT INTO dump_Data
SELECT
*
FROM
JSON_TABLE ( p_clob
COLUMNS
customertransactionid VARCHAR2 ( 300 ) PATH '$.CustomerTransactionId',
duedate VARCHAR2 ( 50 ) PATH '$.DueDate',
conversiondate VARCHAR2 ( 20 ) PATH '$.ConversionDate',
conversionrate NUMBER PATH '$.InvoiceCurrencyCode',
specialinstructions NUMBER PATH '$.SpecialInstructions',
crossreference VARCHAR2 ( 50 ) PATH '$.CrossReference',
documentnumber VARCHAR2 ( 20 ) PATH '$.DocumentNumber',
transactionnumber NUMBER PATH '$.TransactionNumber',
transactiondate DATE PATH '$.TransactionDate',
);
COMMIT;
How can I structure the receivableInvoiecLines section in above select and insert 4 rows in the table?
You can use nesting for this, eg