如何更新oracle sql列中已存在的值

时间:2017-03-17 15:49:39

标签: sql oracle

我试图在我的问题上找到可能的解决方案,但没有成功。假设我有一个包含许多记录的TEST表,其中一列称为CA_GROUP。该列包含以下值:

{"TEST1":"1","TEST2":"2"}

我想将此部分',“TEST3”:“3”添加到该列中已存在的值。所以结果应该是:

{"TEST1":"1","TEST2":"2","TEST3":"3"}

我唯一知道的是:

update test t 
set t.ca_group = replace(t.ca:group, '{"TEST1":"1","TEST2":"2"}'
   , '{"TEST1":"1","TEST2":"2","TEST3":"3"}') 
where id = xxxxxx 
and other conditions.

update test t 
set t.ca_group = replace (t.ca:group, '{"CODE1":"1","CODE2":"2"}'
    , '{"CODE1":"1","CODE2":"2","TEST3":"3"}') 
where id = xxxxxx 
and other conditions.

但这对我来说效率不高,因为我有很多记录,我需要逐个在所有列中添加相同的值。有没有最聪明的方法呢?

1 个答案:

答案 0 :(得分:0)

如何追加' TEST3'每个现有价值?

.container {
  width: 320px;
  height: 480px;
  background: black;
  padding:15px;
  margin: 20px auto;
  display: flex;
}

.grid {
  background: white;
  display: flex;
  width: 100%;
  justify-content: flex-start;
  align-items: flex-start;
  flex-direction: row;
  flex-wrap: wrap;
}

.item {
  width: 100%;
  flex-grow: 0;
  flex-basis: 100%;
  align-self: auto;
  align-items: flex-start;
  padding: 10px 0;
}

.red { background: red; }
.yellow { background: yellow; }
.blue { background: blue; }
相关问题