Beginner

100. REPLACE Function

Learn how to replace one piece of text with another using the REPLACE function.

📘 Lesson 100 of 728 ⏱ 8 min 🎯 Beginner

The REPLACE function searches a string for a specified text pattern and replaces matching occurrences with another text value.

Business data may contain unwanted characters, outdated labels, inconsistent formatting, or incorrect text. REPLACE can help clean and standardize these values.

If a dataset contains department values such as 'Human Resources' and the report requires 'HR', REPLACE can transform the text in the query result.

SQL
SELECT
    REPLACE(Department, 'Human Resources', 'HR') AS DepartmentName
FROM Employees;

REPLACE is useful for cleaning addresses, standardizing labels, removing unwanted characters, correcting text patterns, and preparing data for reports.

  • REPLACE substitutes matching text.
  • It can replace one string with another.
  • It is useful for text cleaning.
  • It can be used in SELECT expressions.
  • Database-specific behavior may vary.
What does REPLACE do in SQL?

REPLACE searches a string for specified text and substitutes matching occurrences with another value.

Can REPLACE be used for data cleaning?

Yes. It can remove or replace unwanted characters, labels, and text patterns.

Have you finished this lesson?

Introduction to SQL – All Lessons