CodesJava

Easy learning with example program codes

REPLACE() FUNCTION in MySQL

REPLACE() FUNCTION
The MySQL REPLACE function is used to replace all occurrences of a substring in a string. The various versions of MySQL supports the REPLACE function, namely, MySQL 5.7, MySQL 5.6, MySQL 5.5, MySQL 5.1, MySQL 5.0, MySQL 4.1, MySQL 4.0 and MySQL 3.23.

Syntax:

REPLACE( string, from_substring, to_substring )

Parameters:
string: It is used to specify the string to check.
from_substring: It is used to specify the substring to replace.
to_substring: It is used to specify the substring to replace with.

Example 1:

mysql> SELECT REPLACE ( ‘HELLO WORLD’, ‘WORLD’, ‘FRIENDS’  );

Output:

‘HELLO FRIENDS’

Explanation:
The specified substring is replaced with another substring.

Example 2:

mysql> SELECT REPLACE ( ‘xyzw xyzw’, ‘x’, ‘w’ );

Output:

‘wyzw wyzw’

Explanation:
The specified substring is replaced with another substring.

Please follow and like us:
error









Copyright © 2019 CodesJava DMCA.com Protection Status