The REPLACE function searches a string for a specified sequence of characters and replaces matching occurrences with another value.
Business data often contains inconsistent characters, formatting, or labels that need to be standardized.
Replace hyphens in a customer reference number.
SELECT
REPLACE(CustomerCode, '-', '') AS CleanCode
FROM Customers;
REPLACE is useful for data cleansing, formatting, standardization, and preparing text for analysis.
- REPLACE substitutes text within a string.
- It can remove unwanted characters.
- It can standardize text values.
- Multiple occurrences may be replaced.
- Syntax can vary slightly between databases.
What does REPLACE do?
REPLACE searches for specified text within a string and substitutes it with another value.
Can REPLACE remove characters?
Yes. Providing an empty replacement value can be used to remove matching characters in supported databases.