我有一种情况,需要动态更新表中的json列。见下面的结构
create table tjson ( jsoncol CLOB CONSTRAINT tjson_chk CHECK (jsoncol IS JSON) );
insert into tjson (jsoncol) VALUES ( '{"name" : "Kunal", "LName" : "Vohra" , "salary" : "10000", "Age" : "25"}');
insert into tjson (jsoncol) VALUES ( '{"name" : "Rahul", "LName" : "Sharma" , "salary" : "20000", "Age" : "35"}');
现在,我需要基于salary
将some_condition
更改为完整表的动态值>
我可以使用JSON_VALUE(jsoncol, '$.Age')
读取数据
update tjson set jsoncol = '"salary":$JustChangeSalary' where some_condition;
薪水是动态的,并不固定。我愿意只改变薪水。
我尝试过json_mergepatch
,但只能从Oracle version 19
中使用。我们正在使用Oracle version 12.2
我有一种情况,需要动态更新表中的json列。参见下面的结构,创建表tjson(jsoncol CLOB CONSTRAINT tjson_chk CHECK(jsoncol IS JSON));插入tjson ...
[假设您要将Kunal的工资更新为15000,然后在WHERE条件下使用JSON_EXISTS()
函数将其过滤掉,并在SET子句旁边使用传统的REPLACE()
函数,其文字摘录包含键-与salary
相关的值组合,如