sqlcmd.net validated sql reference
beginner string-processing MySQL MariaDB SQL Server PostgreSQL SQLite

Replace Text Within A String With REPLACE

Substitute all occurrences of a substring with a new value using `REPLACE`.

Docker-validated Not currently validation-green

Replace a word in message bodies

Every occurrence of 'World' is replaced with 'SQL' in the output. The stored data is not modified — use UPDATE ... SET body = REPLACE(body, 'World', 'SQL') to persist the change.

Rows loaded before the example query runs.
Setup
CREATE TABLE messages (id INT, body VARCHAR(200));

INSERT INTO
  messages (id, body)
VALUES
  (1, 'Hello World'),
  (2, 'World is great');
Shared across supported engines.
SQL
SELECT
  id,
  REPLACE (body, 'World', 'SQL') AS updated_body
FROM
  messages
ORDER BY
  id;
Returned rows for the shared example.
idupdated_body
1Hello SQL
2SQL is great

Output is identical across all engines.

Where this command helps.

  • substituting a word or pattern across multiple rows in a query result
  • cleaning up stored text without modifying the underlying data

What the command is doing.

REPLACE(string, search, replacement) returns a new string with every occurrence of search replaced by replacement. The search is case-sensitive in most engines. It replaces all occurrences, not just the first. REPLACE is useful for cleaning data, fixing typos in bulk, or reformatting stored values.