// strings reference

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.

Categoria
Strings
Returns
string
In this category
7 of 172

Sintaxe

REPLACE(string, find, replacement)

Suporte a mecanismos

MotorSupportNotas
SQL Server Sim Supported under this name.
PostgreSQL Sim Supported under this name.
MySQL Sim Supported under this name.
SQLite Sim Supported under this name.
Oracle Sim Supported under this name.

Exemplos

Any engine

SELECT REPLACE('2026/08/01', '/', '-') AS iso;  -- 2026-08-01

Any engine

SELECT REPLACE(REPLACE(phone, '(', ''), ')', '') AS digits
FROM contacts;

Bom saber

  • 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.

// fewer lookups

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.