SQL REPLACE function
Replaces every occurrence of a literal substring with another string, left to right and non-overlapping. It never treats its arguments as a pattern.
- 카테고리
- Strings
- Returns
string- In this category
- 7 of 172
구문
REPLACE(string, find, replacement)
엔진 지원
| 엔진 | Support | 메모 |
|---|---|---|
| SQL Server | 예 | Supported under this name. |
| PostgreSQL | 예 | Supported under this name. |
| MySQL | 예 | Supported under this name. |
| SQLite | 예 | Supported under this name. |
| Oracle | 예 | Supported under this name. |
예시
Any engine
SELECT REPLACE('2026/08/01', '/', '-') AS iso; -- 2026-08-01
Any engine
SELECT REPLACE(REPLACE(phone, '(', ''), ')', '') AS digits
FROM contacts;
알아 두면 좋은 정보
- The match is literal, not a pattern: REPLACE(s, '%', '') strips percent signs, it does not use wildcards.
- Case sensitivity: SQL Server follows the collation (usually case-insensitive). MySQL's REPLACE matches case-sensitively even under a case-insensitive collation, as do PostgreSQL, SQLite and Oracle.
- Each call swaps one string. To delete several single characters at once, TRANSLATE works on PostgreSQL and Oracle: TRANSLATE(s, 'x()- ', 'x') drops the brackets, dashes and spaces. Otherwise nest REPLACE calls.
- Oracle's third argument is optional: REPLACE(s, '-') deletes every dash.
Questions about REPLACE
Is SQL REPLACE case-sensitive?
On SQL Server it follows the column's collation, which is usually case-insensitive. PostgreSQL, MySQL, SQLite and Oracle match the literal case exactly.
Can REPLACE use wildcards or regex?
No. The search argument is always a literal string. For patterns use REGEXP_REPLACE on PostgreSQL, MySQL 8.0+, Oracle and SQL Server 2025.
Browse every function in the SQL function reference, or see what the SQLly desktop app does for your database.
Related on SQLly
- Regular expression replace in SQL Server, PostgreSQL, MySQL, SQLite and Oracle Dialect comparison
- Generate DROP TABLE statements Snippet
- Remove all whitespace from a string in SQL Snippet
- Replace multiple patterns in one SQL expression Snippet
- Find rows containing control characters Snippet
- Normalize whitespace in SQL Snippet
Cheat sheets for the engines that have it: SQL Server, PostgreSQL, MySQL, SQLite, Oracle.
Functions your engine actually has
SQLly's completion lists the built-in functions of the engine you're connected to, whether that's SQL Server, PostgreSQL, MySQL, SQLite or Oracle. Hover a function for help, and signature hints show each argument as you type.