sql replace function

The SQL replace function is used to replace any string with a new substring. SQL replace is a string function. SQL has many more string functions of which replace is also one.

Related: 25 important examples of SQL where clause

We have some great examples of SQL replace function, after seeing which you will know how to use replace function in SQL.

SQL Replace Function

This function searches the given old string, after finding the string, replaces it with a new string.

/ ***** Single word replace ***** /

SELECT REPLACE('Yellow Car', 'Yellow', 'Blue');
Output:- Blue Car


/ ***** SQL replace multiple characters ***** /

SELECT REPLACE('Yellow Car looking well', 'Yellow Car', 'Blue car');
Output:- Blue car looking well


/ ***** Replace string to numbers ***** /

SELECT REPLACE('Now is the year', 'year', 'year 2020');
Output:- Now is the year 2020


/ ***** Replace single alphabet ***** /

SELECT REPLACE('Demo Demo Demo', 'D', 'C');
Output:- Cemo Cemo Cemo


/ ***** SQL replace function in where clause ***** /

SELECT Replace(name, ' ', ' - ') AS MY_Contacts
FROM Employees
WHERE Replace(name, ' ', ' - ') LIKE 'a%'


/ ***** Replaced column name ***** /

SELECT Replace(address, ' ', ' - ') AS VIP_Address
FROM Employees
WHERE CustomerID <=20;


/ ***** Replace inside update statement ***** /

Update Employees
Set  address = replace(address, 'London', 'California');


/ ***** Replace inside update statement ***** /

Update Employees
SET name = REPLACE(name, 'demo\', '')
WHERE employeeID <=4;

SQL String Functions

We have some of the most commonly used String Functions of SQL available. To explain to you better, we have explained below how to string functions works.

No.FunctionsDescription
1CONCATCombine two strings together
2DIFFERENCEMatch two values
3LOWERUsed to convert a string to lowercase
4UPPERUsed to convert a string to uppercase
5FORMATUsed to apply special format
6TRIMExcludes spaces from a string
7LENTo check the length of string
8REPLACEUsed to replace string with a new substring
9STRReplaces a number as a string
10REVERSEIt reverses the string

SQL Frequently Asked Questions

We have answers to some questions that people search on the Internet every day. Let’s know what those questions are and what their answers are.

What does SQL mean?
SQL stands for Structured Query Language

How to extract data from the database?
Using the “SELECT” statement.

How to update data in the database?
Using the “UPDATE” statement.

How to delete data in the database?
Using the DELETE statement.

What does the replace function do in SQL?
This replace function is used to replace string with a new substring.

How to insert new data in the database?
Using the INSERT INTO statement.

how do you select a column named
Using the “SELECT MyName FROM Mytable” statement.

how do get the full table data?
Using the “SELECT * FROM Mytable” statement.

how do get different or distinct values?
Using the “SELECT DISTINCT ” statement.

how to sort the result?
Using ORDER BY keyword.

how to select a value within a range?
Using the BETWEEN keyword.

how to search for a specific pattern?
Using the LIKE keyword.

how to create a table in the database?
Using the CREATE TABLE keyword.

What does TRIM() Function?
It Removes spaces from a string.

What does the CONCAT() Function?
It Adds two strings together.

What does the LEN() Function?
It returns the length of the string.

What does the REPLICATE() Function?
It repeats the same string.

Related: 20 best examples of SQL like operator