How to update JSON column in oracle 12.1

。_饼干妹妹 提交于 2021-02-10 16:58:21

问题


Am trying to update a JSON column in oracle 12.1. Is there any json function that can be used to update the JSON. I have added a constraint JSON_COLUMN is JSON.

I have tried :

UPDATE tablename SET JSON =
json_mergepatch(JSON, '{"STRUCTURE_NAME":null}');

But this function is applicable only for 19c

This "STRUCTURE_NAME": "ABC:STATE:L12345", needs to be updated with "STRUCTURE_NAME":null

回答1:


Pre-19c, if you want to change any values in a JSON document, you have to replace the whole thing:

create table t (
  doc varchar2(100)
    check ( doc is json ) 
);

insert into t values ('{
  "changeMe" : "to null",
  "leaveMe"  : "alone"
}');

update t
set    doc = '{
  "changeMe" : null,
  "leaveMe"  : "alone"
}';

select * from t;

DOC                                               
{
  "changeMe" : null,
  "leaveMe"  : "alone"
}  

Note that when you get to 19c and use json_mergepatch, setting an attribute to null removes it from the document:

update t
set    doc = json_mergepatch ( 
  doc, 
  '{
    "changeMe" : null
  }');

select * from t;

DOC                   
{"leaveMe":"alone"}   


来源:https://stackoverflow.com/questions/58114909/how-to-update-json-column-in-oracle-12-1

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!