[英]replacing part of a string with value from another column postgresql
[英]Replacing part of string within cell with string from different column
我想用同一个表中使用的列中的值替换单元格中的字符串。
字符串说"your bonus is bonus_score"
,我想用"bonus_score"
列中的数据替换'bonus score'
语句。
表结构:
person_id nvarchar (8),
first_name nvarchar(100),
lastname nvarchar(100),
text nvarchar(max),
text_modified nvarchar(max),
bonus_score decimal(10,2)
编辑:O 错误地解决了这个问题:这里的目的是获得自动解决方案,该解决方案将检测“文本”中的字符串是否包含表中不同列的任何名称并自动替换其中的数据。
您可以使用update
和replace()
:
update t
set text_modified = replace('bonus_score', bonus_score)
where text_modified like '%bonus_score%';
像这样的东西。 这会将 text_nvarchar 列中的字符串 'bonus_score' 替换为来自奖励分数列的值。
update tTable
set text_modified=replace(text_nvarchar, 'bonus_score', bonus_score);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.