如何使用update语句在oracle sql中压缩列中的字符串
我想在oracle SQL中的列中包含一个字符串如何使用update语句在oracle sql中压缩列中的字符串,sql,oracle,Sql,Oracle,我想在oracle SQL中的列中包含一个字符串 Name Info A Age=10,Section='A' B Age=9,Section='B' Demo 我想使用update语句在表Demo的Info列(varchar2(100))中添加字符串费(int),如下所示: Name Info A Age=10,Section='A',fee=1000 B Age=9,Section='B',fee=2000
Name Info
A Age=10,Section='A'
B Age=9,Section='B'
Demo
我想使用update语句在表Demo的Info列(varchar2(100))中添加字符串费(int),如下所示:
Name Info
A Age=10,Section='A',fee=1000
B Age=9,Section='B',fee=2000
Demo
字符串串联运算符是
|
。您可以这样做:
select t.*,
(info || (case when name = 'A' then ',fee=1000'
when name = 'B' then ',fee=2000'
end)
) as new_info
from t;
此逻辑也可以合并到更新中
:
update t
set info = (info || (case when name = 'A' then ',fee=1000'
when name = 'B' then ',fee=2000'
end)
)
where name in ('A', 'B');
这是仅用于报告,还是要将数据以该格式存储在数据库的表中?如果仅用于报告,则罚款;但是,如果您正在考虑将数据以那种格式存储在数据库中,就像您所提到的
update
,这是一个可怕的想法。阅读第一个标准表单以了解原因。计算费用的逻辑是什么?如何使用update语句