I have a CLOB column containing JSON, I want to update the values of the JSON using json_mergepatch. If the column is NULL then json_mergepatch doesn't work, so in this case I just want to add the new JSON as given.
I must use CLOB to avoid this issue: Oracle Update - JSON Merge Patch with more than 4000 characters
This works and updates the column:
UPDATE my_table SET data =
json_mergepatch(data, '{ "user": "Tony" }' RETURNING CLOB)
where id = '1';
This gives ORA-00932: inconsistent datatypes: expected CHAR got CLOB:
UPDATE my_table SET data =
case
when (data is NULL) then '{ "user": "Tony" }'
else json_mergepatch(data, '{ "user": "Tony" }' RETURNING CLOB)
end
where id = '1';
Why doesn't it work with case? How can I fix it?