Replace all occurrences of a substring within a string with a new substring.
REPLACE(str, from, to) returns str with all occurrences of 'from' replaced by 'to'. It is non-destructive and differs from REGEXP_REPLACE, which uses regular expressions for pattern matching. Note that REPLACE INTO is a separate DML statement for upsert operations (deletes and inserts on unique key conflicts), not related to this string function.
| Database System | Support Status | Since Version | Notes |
|---|---|---|---|
| MySQL | ✓ Supported | all | REPLACE(str, from_str, to_str). Case-sensitive (regardless of collation). Replaces all occurrences. |
| PostgreSQL | ✓ Supported | all | REPLACE(str, from, to). Case-sensitive. For case-insensitive replace, use REGEXP_REPLACE with the 'i' flag. |
| SQL Server | ✓ Supported | all | REPLACE(str, old, new). Case sensitivity depends on the database collation. In a case-insensitive collation, REPLACE('Hello', 'hello', 'X') returns 'X'. |
| Oracle | ✓ Supported | all | REPLACE(str, search [, replacement]). If replacement is omitted or NULL, all occurrences of search are deleted. Case-sensitive. |
| SQLite | ✓ Supported | all | REPLACE(str, old, new). Case-sensitive. Replaces all occurrences. |
All five engines support REPLACE with the same three-argument signature. Case sensitivity is the key difference: MySQL is always case-sensitive, SQL Server follows collation, PostgreSQL is always case-sensitive (use REGEXP_REPLACE with 'i' flag for case-insensitive). Oracle's optional third argument (deletion mode) is unique.
REPLACE(str, from_str, to_str). Case-sensitive (regardless of collation). Replaces all occurrences.
REPLACE(str, from, to). Case-sensitive. For case-insensitive replace, use REGEXP_REPLACE with the 'i' flag.
REPLACE(str, old, new). Case sensitivity depends on the database collation. In a case-insensitive collation, REPLACE('Hello', 'hello', 'X') returns 'X'.
REPLACE(str, search [, replacement]). If replacement is omitted or NULL, all occurrences of search are deleted. Case-sensitive.
REPLACE(str, old, new). Case-sensitive. Replaces all occurrences.