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類型字段的替換

熱門標籤