Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Oracle SQL: JSON query

I have below JSON in 12c Oracle table

[
  {
    "od": "2022-01-01",
    "md": "2022-01-01",
    "di": 2.1
  },
  {
    "od": "2022-02-02",
    "md": "2022-02-02",
    "di": 3.1
  },
  {
    "od": "2022-02-03",
    "md": "2022-02-03",
    "di": 4.1
  }
]

od= order_date, md=modified_date, di= discount

Expected output

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

od md di
2022-01-01 2022-01-01 2.10
2022-02-02 2022-02-02 3.10
2022-02-03 2022-02-03 4.10

I tried JSON_VALUE(ORDER_DATA, '$.di' ) it gives me null

I tried JSON_TABLE() as below but then too it gives me null

SELECT j.id, jt.di 
  FROM order_date j, 
       JSON_TABLE(
                  j.json_order_data, 
                  '$' COLUMNS (
                                di number(10) PATH '$.di[*]'
                              )
                 ) jt;

JSON_EXTRACT() does not work in oracle

I have tried that as well, can anyone please help me for this SQL query?

>Solution :

Use it in this way:

SELECT j.id, jt.di 
  FROM ORDER_DATE j, 
       json_table(j.JSON_ORDER_DATA, '$[*]' 
        COLUMNS (
          di number(10) PATH '$.di'
        )) jt;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading