The REPLACE function searches a text value for a specified substring and replaces matching occurrences with another value.
Text data often needs standardization or correction before it can be used reliably in reports and analysis.
Replace spaces in product codes with hyphens.
SELECT
REPLACE(ProductCode, ' ', '-') AS ProductCode
FROM Products;
REPLACE is useful for data cleansing, formatting, standardization, correcting imported values, and preparing text for analysis.
- REPLACE substitutes matching text.
- It can replace multiple occurrences.
- It is useful for data cleaning.
- It normally returns a transformed value without modifying the source table.
- Syntax and behavior can vary slightly between databases.
What does REPLACE do in SQL?
REPLACE searches for a specified substring and substitutes it with another value.
Does REPLACE permanently change table data?
No. REPLACE inside SELECT only transforms the value returned by the query. Permanent changes require an UPDATE statement.