I'm trying to generate a JSON from an SQL with PL/JSON
declare
customer json_list := json_list();
product json_list;
begin
customer:= json_dyn.executeList('SELECT DISTINCT
A.customer_id,
A.customer_name,
FROM customer A
WHERE A.customer_id = 1');
product := json_dyn.executeList('SELECT DISTINCT
A.product_id,
A.product_name,
FROM sales A
INNER JOIN customer B
ON A.customer_id = B.customer_id
WHERE A.customer_id = 1');
end;
What I need is to join these two select to become a single JSON and look like this: In a way where product is a sales key and the value of product is a list of products
[
{
"customer_id": 1,
"customer_name": "Customer A",
"product": [
{
"product_id": 5715,
"product_name": "Product A",
},
{
"product_id": 7841,
"product_name": "Product B",
}
]
}
]
does anyone know how to do it that way?
I'm supposing the "list" come from some table:
HTH.