Tutorial Gateway

  • C
  • C#
  • Java
  • Python
  • SQL
  • MySQL
  • Js
  • BI Tools
    • Informatica
    • Talend
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • R Tutorial
    • Alteryx
    • QlikView
  • More
    • C Programs
    • C++ Programs
    • Go Programs
    • Python Programs
    • Java Programs

MySQL REPLACE Function

by suresh

The MySQL REPLACE function is one of the String Function, which is useful to replace the existing string expression with a new string value. The basic syntax of string Replace in MySQL is as shown below:

SELECT REPLACE (Expression, Change_String, Replace_String)
FROM Source
  • Expression: Please specify the valid expression on which you want to perform the search. Replace function replace a portion of a string present here.
  • Change_String: Specify any valid string (or character) you want to change. Whatever you place here, REPLACE Function will replace it by Replace_String
  • Replace_String: Please specify the valid new string or charter that you want to insert into String_Expression.

For this MySQL String REPLACE demonstration, We are going to use the below shown data

MySQL String Replace Function Example

MySQL Replace String Example 1

The String Replace Function is used to replace the characters in the original string with the specified expression. The below query shows various ways to use this String replace function.

-- MySQL String Replace Function Example
SELECT REPLACE('Tutorial Gateway', 'Tutorial', 'MySQL');

SELECT REPLACE('www.tutorialgateway.org', 'org', 'net');

-- Let me Try with Integer values
SELECT REPLACE('123456', 34, 75);

SELECT REPLACE(123456, 234, 379);

-- Testing NULLS
SELECT REPLACE('Tutorial', 'Tu', NULL);
MySQL Replace String Function Example 1

Replace String Example 2

In this example, we implement the string replace function on different columns present in the employee table. The following String Function statement replaces the string Developer in Department Name column with Engineer and com in Email with net

-- MySQL String REPLACE Example
USE mysqltutorial;
SELECT FirstName,
	   LastName,
       DepartmentName,
       REPLACE(DepartmentName, 'Developer', 'Engineer') AS `Replaced Dept`,
       Email,
       REPLACE(Email, 'com', 'net') AS `Replaced Email`
FROM employe;

From the below MySQL screenshot you can see the replaced strings

MySQL Replace String Function Example 2

Placed Under: MySQL

  • How to Download MySQL
  • Install MySQL on Windows
  • MySQL Create Database
  • MySQL Delete Database
  • MySQL Create Table
  • MySQL Drop Table
  • MySQL SELECT Statement
  • MySQL ALIAS Column
  • MySQL Distinct
  • MySQL Insert Statement
  • MySQL Delete
  • MySQL Truncate Table
  • MySQL WHERE Clause
  • MySQL Order By
  • MySQL Group By
  • MySQL Having Clause
  • MySQL LIMIT
  • MySQL Arithmetic Operators
  • MySQL COALESCE Function
  • MySQL AND Operator
  • MySQL NOT Operator
  • MySQL OR Operator
  • MySQL XOR Operator
  • MySQL BETWEEN Operator
  • MySQL Not Between Operator
  • MySQL GREATEST Function
  • MYSQL LEAST Function
  • MySQL LIKE Operator
  • MySQL NOT LIKE Operator
  • MySQL IFNULL Operator
  • MySQL NULLIF Operator
  • MySQL INTERVAL Operator
  • MySQL IS Operator
  • MySQL IN Operator
  • MySQL NOT IN Operator
  • MySQL IS NOT NULL
  • MySQL IS NULL
  • MySQL Inner Join
  • MySQL Cross Join
  • MySQL Right Join
  • MySQL Left Join
  • MySQL Aggregate Functions
  • MySQL Date Functions
  • MySQL Date Function
  • MySQL String Functions
  • MySQL Numeric Functions

Copyright © 2021 · All Rights Reserved by Suresh

About Us | Contact Us | Privacy Policy