replaces all occurrences of a specified string value with another string value.
文法:
replace ( string_expression , string_pattern , string_replacement )
參數:
string_expression
is the string expression to be searched. string_expression can be of a character or binary data type.
string_pattern
is the substring to be found. string_pattern can be of a character or binary data type. string_pattern cannot be an empty string (''), and must not exceed the maximum number of bytes that fits on a page.
string_replacement
is the replacement string. string_replacement can be of a character or binary data type.
傳回
returns nvarchar if one of the input arguments is of the nvarchar data type; otherwise, replace returns varchar.
returns null if any one of the arguments is null.
if string_expression is not of type varchar(max) or nvarchar(max), replace truncates the return value at 8,000 bytes. to return values greater than 8,000 bytes, string_expression must be explicitly cast to a large-value data type.
即用第三個表達式替換第一個字元串表達式中出現的所有第二個給定字元串表達式。
例子:
select replace('aaaaaxxxaaa','x','a');
結果: