REPLACE
functionsupportedCore SQL functionsRemoves all occurrences of a specified substring, and optionally replaces them with another substring.
Syntax
REPLACE( <subject> , <pattern> [ , <replacement> ] )
Parameters
| Name | Required | Description |
|---|---|---|
subject | required | The subject is the string in which to do the replacements. Typically, this is a column, but it can be a literal. |
pattern | required | This is the substring that you want to replace. Typically, this is a literal, but it can be a column or expression. Note that this is not a “regular expression”; if you want to use regular expressions to search for a pattern, use the REGEXP_REPLACE function. |
replacement | required | This is the value used as a replacement for the pattern. If this is omitted, or is an empty string, then the REPLACE function simply deletes all occurrences of the pattern. |
Returns
The returned value is the string after all replacements have been done.
Usage notes
- If replacement is not specified, subject is returned with all occurrences of pattern removed.
- If replacement is specified, subject is returned with all occurrences of pattern replaced by replacement.
- If any of the arguments is a NULL, the result is also a NULL.
- Note
- Only occurrences in the original subject are considered. A pattern that occurs in the result is not removed/replaced.
Collation details
The collation specifications of all input arguments must be compatible. This function does not support the following collation specifications: - pi (punctuation-insensitive). - cs-ai (case-sensitive, accent-insensitive).