問(wèn)題描述
替換列中字符串的最佳方法是什么:
假設(shè)我有一個(gè)列類型為 varchar
的表,可能的值包含:
注意:我的價(jià)值可能會(huì)有所不同.
現(xiàn)在我想將其替換為:
所以在這種情況下的最終值是:
我想對(duì)整個(gè)表執(zhí)行更新.
是否可以使用純 T-SQL?
所以 => 之前和轉(zhuǎn)換之后的兩個(gè)示例行:
<代碼>1.值為:min(10).=>值為: min(max(10))2. 樣本 min(cat) =>樣本最小值(最大值(貓))
基本上用min(max(value))
替換所有出現(xiàn)的min(value)
,其中'value'
可以是任何字符串
首先你需要這個(gè)用戶定義的函數(shù)來(lái)搜索用字符串替換模式:
閱讀更多
min(xxx) 出現(xiàn)不止一次:
最后,您可以簡(jiǎn)單地更新您的表格,如下所示:
What is the best way to replace string in column like:
Let's say I have table with column type varchar
and with the possible value that contains:
Note: my value can vary.
Now I would like to replace it with:
so that the final value would in that case be:
I would like to perform update on the whole table.
Is it possible using pure T-SQL?
So two sample rows before => and after transformation:
Basically replace all occurrences of min(value)
with min(max(value))
where 'value'
can be any string
First of all you need this user defined function to search for replacing a pattern with string:
Read more here
After creating this function you can try this:
And you can see that the output is:
Occurrence of min(xxx) more than once:
Finally you can simply update your table as below:
這篇關(guān)于SQL Server 2014 替換為正則表達(dá)式的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!