I'm storing a java class A as A_DOC in a clob column in my database.
The structure of A is like:
{
id : 123
var1: abc
subvalues : [{
id: 1
value : a
},
{
id: 1
value :b
}
...
}
]}
I know I can do things like
select json_query(a.A_DOC, '$.subvalues.value') from table_name a;
and so on, but how I'm looking for a way to count the number of elements in the subvalues array through an sql query. Is this possible?
JSON can be stored as VARCHAR2 (up to 32767 bytes), CLOB and BLOB. CLOB and BLOB have no length limitations.
In addition to the simplified syntax, Oracle Database 12c adds support for SQL/JSON, an extension to the SQL standard that allows the content of JSON documents to be queried as part of a SQL operation.
You can create a table that has JSON columns. You use SQL condition is json as a check constraint to ensure that data inserted into a column is (well-formed) JSON data. Oracle recommends that you always use an is_json check constraint when you create a column intended for JSON data.
the function exists in Oracle 18 only
SELECT json_query('[19, 15, [16,2,3]]','$[*].size()' WITH ARRAY WRAPPER) FROM dual;
SELECT json_value('[19, 15, [16,2,3]]','$.size()') FROM dual;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With