SqlServer中REPLACE函式的使用

來源:魅力女性吧 1.5W
SqlServer中REPLACE函式的使用

Sql Server REPLACE函式的使用

REPLACE

用第三個表示式替換第一個字串表示式中出現的所有第二個給定字串表示式。

語法

REPLACE ( ''string_replace1'' , ''string_replace2'' , ''string_replace3'' )

引數

''string_replace1''

待搜尋的字串表示式。string_replace1 可以是字元資料或二進位制資料。

''string_replace2''

查詢的字串表示式。string_replace2 可以是字元資料或二進位制資料。

''string_replace3''

替換用的字串表示式。string_replace3 可以是字元資料或二進位制資料。

返回型別

如果 string_replace(1、2 或 3)是支援的字元資料型別之一,則返回字元資料。如果 string_replace(1、2 或 3)是支援的 binary 資料型別之一,則返回二進位制資料。

示例

下例用 xxx 替換 abcdefghi 中的字串 cde。

SELECT REPLACE(''abcdefghicde'',''cde'',''xxx'')GO

下面是結果集:

------------abxxxfghixxx(1 row(s) affected)

這個函式有一點不足是不支援 text,ntext型別欄位的替換

熱門標籤