天天看點

Sql Server 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)

本文轉自9pc9com部落格,原文連結:       http://blog.51cto.com/215363/746459 如需轉載請自行聯系原作者