![](/img/trans.png)
[英]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.