MySQL: REPLACE Function

  • Post author:
  • Post category:MySQL
  • Post comments:1 Comment
MySQL REPLACE Function

In this guide, we will explain how to use the MySQL REPLACE function with syntax and examples.

Description

The MySQL REPLACE function replaces all occurrences of a specified string.

Syntax

The syntax for the REPLACE function in MySQL is:

REPLACE( string, from_substring, to_substring )

Parameters or Arguments

string

The source string.

from_substring

The substring to find. All occurrences of from_substring found within string are replaced with to_substring.

to_substring

The replacement substring. All occurrences of from_substring found within string are replaced with to_substring.

Note

  • The REPLACE function performs a case-sensitive replacement.

Applies To

The REPLACE function can be used in the following versions of :

  • MySQL 5.7, MySQL 5.6, MySQL 5.5, MySQL 5.1, MySQL 5.0, MySQL 4.1, MySQL 4.0, MySQL 3.23

Example

Let’s look at some REPLACE function examples and explore how to use the REPLACE function.

For example:

mysql> SELECT REPLACE('adglob.in', 'adglob', 'baldevinfo');
Result: 'baldevinfo.in'

mysql> SELECT REPLACE('AdGlOb.in', 'adglob', 'baldevinfo');
Result: 'AdGlOb.in'

mysql> SELECT REPLACE('abc abc', 'a', 'B');
Result: 'Bbc Bbc'

mysql> SELECT REPLACE('abc abc', 'A', 'B');
Result: 'abc abc'

mysql> SELECT REPLACE('123 123', 2, 5);
Result: '153 153'

Next Topic : Click Here

This Post Has One Comment

Leave a Reply