Data Loader

REPLACE Function in MS SQL Server and MySQL

The REPLACE function is used to change a string pattern with another string pattern in a given string expression.

The Replace function is available in both MSSQL and MySQL and it's functionality is also same except that MSSQL REPLACE function does case insensitive searches and replaces the string in any case whereas in MySQL it is case sensitive.

 Here is the syntax and examples of both MSSQL and MySQL

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 has changed both Win10 and win o/s to Windows irrespective of case.

MySQL

In MySQL also REPLACE function does the same job but it is case sensitive. See example below

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 |
+---------------------------------------------------------------+
1 row in set (0.00 sec)

mysql>

Notice that it has not changed Win10 because we passed lowercase 'win' as string pattern to be sought.

REPLACE function in MySQL
 

Back to Converting Functions from MSSQL to MySQL