更新json列oracle v12.2

问题描述 投票:1回答:1

我有一种情况,需要动态更新表中的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"}');

现在,我需要基于salarysome_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 ...

database oracle updates oracle12c insert-update
1个回答
0
投票

[假设您要将Kunal的工资更新为15000,然后在WHERE条件下使用JSON_EXISTS()函数将其过滤掉,并在SET子句旁边使用传统的REPLACE()函数,其文字摘录包含键-与salary相关的值组合,如

© www.soinside.com 2019 - 2024. All rights reserved.