JSON_OBJECT, JSON_ARRAYAGG

Zapisywanie danych w formacie JSON na bazie danych z tabel Oracle

select json_object(s.shipment_nr,
'RouteNumber' is t2.col1,
'LoadedDate' is to_char(sysdate, 'YYYY-MM-DD') || 'T' ||
to_char(sysdate, 'HH24:MI:SS'),
'Logunits' is
(select json_arrayagg(json_object(t.col2,
t.col3,
t.col4))
from table_ship_lu t
where t.ship_id = t2.ship_id))
from table_ship t2
where t2.ship_id = 12345678;

Rezultat:

{
"LoadedDate": "2026-01-04T21:57:49",
"Logunits": [
{
"col2": "FL",
"col2": "1823907152",
"col2: "CL"
},
{
"col2": "FL",
"col2": "1823907153",
"col2: "CL"
}
],
"RouteNumber": "RouteNumber",
"shipment_nr": "12345678"
}

Tags: