3 回答

TA貢獻(xiàn)1936條經(jīng)驗(yàn) 獲得超7個(gè)贊
我可能會誤會,但您有兩組數(shù)據(jù)要從一組中刪除數(shù)據(jù)庫中當(dāng)前數(shù)據(jù)的字符串,然后在每次導(dǎo)入時(shí)都從一組中刪除字符串。
對于更新現(xiàn)有記錄,我只會使用SQL,那只需要發(fā)生一次。
但是,SQL并未針對這種操作進(jìn)行優(yōu)化,因?yàn)槟f的是編寫導(dǎo)入實(shí)用程序,所以我將在導(dǎo)入實(shí)用程序本身而不是在SQL中進(jìn)行這些更新。這將是更好的性能選擇。您在用什么編寫實(shí)用程序?
另外,我可能會完全誤解該過程,因此,如果我偏離基準(zhǔn),我深表歉意。
編輯:
對于初始更新,如果您使用的是SQL Server 2005,則可以嘗試CLR函數(shù)。這是一個(gè)使用正則表達(dá)式的快速方法。不確定性能如何進(jìn)行比較,我自己從未使用過此功能,除非現(xiàn)在進(jìn)行快速測試。
using System;
using System.Data;
using System.Text.RegularExpressions;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
public partial class UserDefinedFunctions
{
[Microsoft.SqlServer.Server.SqlFunction]
public static SqlString StripNonNumeric(SqlString input)
{
Regex regEx = new Regex(@"\D");
return regEx.Replace(input.Value, "");
}
};
部署之后,可以使用以下命令進(jìn)行更新:
UPDATE table SET phoneNumber = dbo.StripNonNumeric(phoneNumber)

TA貢獻(xiàn)1796條經(jīng)驗(yàn) 獲得超10個(gè)贊
我看到了帶有T-SQL代碼和PATINDEX的解決方案。我喜歡 :-)
CREATE Function [fnRemoveNonNumericCharacters](@strText VARCHAR(1000))
RETURNS VARCHAR(1000)
AS
BEGIN
WHILE PATINDEX('%[^0-9]%', @strText) > 0
BEGIN
SET @strText = STUFF(@strText, PATINDEX('%[^0-9]%', @strText), 1, '')
END
RETURN @strText
END

TA貢獻(xiàn)1851條經(jīng)驗(yàn) 獲得超3個(gè)贊
replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(string,'a',''),'b',''),'c',''),'d',''),'e',''),'f',''),'g',''),'h',''),'i',''),'j',''),'k',''),'l',''),'m',''),'n',''),'o',''),'p',''),'q',''),'r',''),'s',''),'t',''),'u',''),'v',''),'w',''),'x',''),'y',''),'z',''),'A',''),'B',''),'C',''),'D',''),'E',''),'F',''),'G',''),'H',''),'I',''),'J',''),'K',''),'L',''),'M',''),'N',''),'O',''),'P',''),'Q',''),'R',''),'S',''),'T',''),'U',''),'V',''),'W',''),'X',''),'Y',''),'Z','')*1 AS string,
:)
- 3 回答
- 0 關(guān)注
- 1687 瀏覽
添加回答
舉報(bào)