How to Replace Part of a String in SQL Database: SQL PostgreSQL Oracle MS SQL Server MySQL SQLite Operators: REPLACE Table of Contents Problem: Example: Solution: Discussion: Problem: You’d like to replace part of a string with another string. Example: Our database has a table named investor with data in the following columns: id, company, and phone. idcompanyphone 1Big Market123–300-400 3The Sunny Restaurant123–222-456 4My Bank123-345-400 We’d like to change the phone number format for each company by replacing the hyphen character with a space. Solution: SELECT REPLACE(phone, '-', ' ') as new_phone FROM investor; The query returns a list of phone numbers with spaces instead of hyphens as separators: new_phone 123 300 400 123 222 456 123 345 400 Discussion: If you’d like to replace a substring with another string, simply use the REPLACE function. This function takes three arguments: The string to change (which in our case was a column). The substring to replace. The string with which to replace the specified substring. In the next example, we replace the adjective 'Big' in the company column with 'Small'. SELECT REPLACE( company, 'Big', 'Small' ) as new_company FROM investor WHERE id = 1; This query display the new name of the company for the investor with id = 1. new_company Small Market Recommended courses: SQL Basics SQL Practice Set Standard SQL Functions Recommended articles: Standard SQL Functions Cheat Sheet 5 SQL Functions for Manipulating Strings 18 Useful Important SQL Functions to Learn ASAP SQL String Functions: A Complete Overview See also: How to Trim Strings in SQL Subscribe to our newsletter Join our monthly newsletter to be notified about the latest posts. Email address How Do You Write a SELECT Statement in SQL? What Is a Foreign Key in SQL? Enumerate and Explain All the Basic Elements of an SQL Query