replace function in sql

REPLACE() Function in SQL

In this tutorial, we will learn about REPLACE() Function in SQL. For learning this further, we have to be familiar with SQL.
SQL stands for Structured Query Language. It is used to create and access data from the database. For accessing the data from the database in SQL, we have to write a query. The query is basically a SELECT statement that is used to access the data from the database.

REPLACE() Function in SQL

To get more details regarding below topics :

How to create a database in SQL
How to write the query in SQL

What is REPLACE() Function in SQL

REPLACE() function is used to replace your specified character or substring with your new character or substring. This function is used to replace all the occurrences of your old character or substring with your new character or substring.

SQL REPLACE() function Syntax

REPLACE(string, replaceable string, new string)

string: String is the main string whose character or substring you want to replace.

replaceable string: Character or substring which would be replaced

new string: New character or substring which will replace the replaceable string.

Let’s understand with the help of some examples :

Example 1:

SELECT REPLACE('developerhelps','e','a') as replace

Output:

replace
davaloparhalps

It replaces all the occurrences of the ‘e’ character with ‘a’ character.

Example 2:

SELECT REPLACE('developerhelps','helps','s') as replace

Output:

replace
developers

Example 3:

SELECT REPLACE('DaDada','D','e') as replace

Output:

replace
eaeada

It is clear from the above example, replace() function is case sensitive function.