SQL REPLACE()

Anonymous contributor's avatar
Anonymous contributor
Published Oct 1, 2024
Contribute to Docs

The REPLACE() function replaces all matching parts of a string with a specified new substring.

  • Learn to analyze data with SQL and prepare for technical interviews.
    • Includes 9 Courses
    • With Certificate
    • Beginner Friendly.
      18 hours
  • In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.
    • Beginner Friendly.
      5 hours

Syntax

REPLACE("string_expression", "old_substring", "new_substring");

The REPLACE() function searches for all occurrences of the old_substring in the string_expression and replaces it with new_substring.

Note: All parameters are required.

Example

In this example, “cool” is replaced with “amazing”:

SELECT REPLACE("SQL is cool", "cool", "amazing");

The above query will give the following output:

SQL is amazing

All contributors

Contribute to Docs

Learn SQL on Codecademy

  • Learn to analyze data with SQL and prepare for technical interviews.
    • Includes 9 Courses
    • With Certificate
    • Beginner Friendly.
      18 hours
  • In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.
    • Beginner Friendly.
      5 hours