I have a table with a CLOB that stores a big JSON payload. I cannot however select certain attributes whose value is greater than 4000 bytes.
For example, take a json like this:
{
"foo": "some string smaller than 4k",
"bar": "some string larger than 4k"
}
The following works:
SELECT json_value(j, '$.foo' ERROR ON ERROR) FROM j;
The following fails with ORA-40478: output value too large (maximum:)
:
SELECT json_value(j, '$.bar' ERROR ON ERROR) FROM j;
From this 12CR1 documentation:
ORA-40478: output value too large (maximum: string)
Cause: The provided JavaScript Object Notation (JSON) operator generated a result which exceeds the maximum length specified in the RETURN clause.
Action: Increase the maximum size of the data type in the RETURNING clause or use a CLOB or BLOB in the RETURNING clause.
However, using the RETURNING
clause fails as well, with ORA-40444: JSON processing error
:
SELECT json_value(j, '$.bar' RETURNING CLOB ERROR ON ERROR) FROM j;
It also fails during PLSQL
DECLARE
val CLOB;
BEGIN
SELECT json_value(j, '$.bar' RETURNING CLOB ERROR ON ERROR)
INTO val
FROM j
END;
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.
SQL/JSON function json_value selects a scalar value from JSON data and returns it as a SQL value. You can also use json_value to create function-based B-tree indexes for use with JSON data — see Indexes for JSON Data. Function json_value has two required arguments and accepts optional returning and error clauses.
Json_value function by default will return varchar2(4000), but if you add returning clause with specified varchar2 size you can force it to return much longer values.
In your example the following query should works:
SELECT json_value(j, '$.bar' returning varchar2(32000) ERROR ON ERROR) FROM j;
PS. In Oracle 12c (SQL) varchar2 is limited to 4000 bytes unless you set MAX_STRING_SIZE parameter to EXTENDED.
32767 bytes or characters if MAX_STRING_SIZE = EXTENDED
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