REPLACE Function in MS SQL Server and MySQL


The REPLACE function changes a string pattern with another string pattern in a given string expression. It's available in both MSSQL and MySQL with the same core functionality — except MSSQL REPLACE does case-insensitive searches, while MySQL's is case-sensitive.

MSSQL

Syntax:

REPLACE ( string_expression , string_pattern , string_replacement )

Example:

select replace('Win10 is latest version of win o/s','win','Windows')
---------------------------------------------
Windows10 is latest version of Windows o/s

Replace function in MSSQL

Notice that it changed both "Win10" and "win o/s" to "Windows" irrespective of case.

MySQL

In MySQL, REPLACE does the same job but is case-sensitive.

Syntax:

REPLACE ( string_expression , str_sought , str_replacement )

Example:

mysql> select replace('Win10 is latest version of win o/s','win','Windows');
+-----------------------------------------------------------------+
| replace('Win10 is latest version of win o/s','win','Windows')   |
+-----------------------------------------------------------------+
| Win10 is latest version of Windows o/s                          |
+-----------------------------------------------------------------+

Notice that it didn't change "Win10", because we passed lowercase 'win' as the pattern to search for.

REPLACE function in MySQL

Back to Converting Functions from MSSQL to MySQL