REPLACE is a scalar string function defined by the SQL standard. It scans an input string for every occurrence of a search substring and substitutes each match with a replacement substring, returning the transformed value. The operation is case-sensitive or case-insensitive depending on the database collation.Key points:- Non-destructive: REPLACE does not alter data in place; it only returns a modified result. To persist changes, wrap it in UPDATE.- Global substitution: All occurrences are replaced, not just the first.- Null handling: If any argument is NULL, the function returns NULL.- Data types: Arguments must be character types (CHAR, VARCHAR, TEXT, etc.). Some systems implicitly cast numbers to strings.- Collation awareness: In case-insensitive collations, 'ABC' and 'abc' are treated the same for matching.- Multibyte safety: Most databases operate on characters, not bytes, so UTF-8 strings are handled correctly.- Performance: On large text columns, REPLACE may force a full scan and produce large temporary values; index use is limited.
source_string
(STRING) - The original text to search withinsearch_substring
(STRING) - The text to find. An empty string returns source_string unchanged.replacement_substring
(STRING) - The text that will replace each occurrence.UPDATE, REGEXP_REPLACE, TRANSLATE, SUBSTRING, TRIM
SQL-92 standard
No. It only returns a transformed value. Use an UPDATE statement to store the result back into the table.
Yes, because it performs simple literal matching. Regular-expression functions add parsing overhead and should be used only when pattern matching is required.
Absolutely. Specify an empty string ('') as the replacement to delete all occurrences of the search substring.
If any of source_string, search_substring, or replacement_substring is NULL, the output is NULL. Ensure none of the inputs are NULL before calling REPLACE.