SqlServer中REPLACE函數的使用
來源:魅力女性吧 1.5W
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類型字段的替換