0

I have JSON as below,

{
  "value": [
    {
      "id": "123",
      "createdDateTime": "2021-09-17T14:15:18Z"
    },
    {
      "id": "124",
      "createdDateTime": "2022-09-17T14:15:18Z"
    }
  ]
}

am trying to get the output as 2 separate records and store it in clob column(values), any help would be appreciated.

values
{"id": "123",
"createdDateTime": "2021-09-17T14:15:18Z"
}
{"id": "123",
"createdDateTime": "2021-09-17T14:15:18Z"
}

1 Answer 1

1

You can use JSON_TABLE:

SELECT j.value
FROM   table_name t
       CROSS APPLY JSON_TABLE(
         t.json_value,
         '$.value[*]'
         COLUMNS
           value VARCHAR2(4000) FORMAT JSON PATH '$'
       ) j

Which, for the sample data:

CREATE TABLE table_name (json_value CLOB CHECK (json_value IS JSON));

INSERT INTO table_name (json_value)
VALUES ('{"value":[{
            "id": "123",
            "createdDateTime": "2021-09-17T14:15:18Z"
            
        },
        {
            "id": "124",
            "createdDateTime": "2022-09-17T14:15:18Z"
            
        }]}')

Outputs:

VALUE
{"id":"123","createdDateTime":"2021-09-17T14:15:18Z"}
{"id":"124","createdDateTime":"2022-09-17T14:15:18Z"}

db<>fiddle here

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, it works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.