Welcome to plsql4all.blogspot.com SQL, MYSQL, ORACLE, TERADATA, MONGODB, MARIADB, GREENPLUM, DB2, POSTGRESQL.

Friday, 23 February 2024

Replace Function in MYSQL

In MySQL, the REPLACE function is used to replace all occurrences of a specified substring within a string with another substring. It's similar to the REPLACE function in Oracle and SQL Server.


Here's the syntax of the REPLACE function in MySQL:


REPLACE(original_string, old_substring, new_substring)


- original_string: The string in which to perform the replacement.

- old_substring: The substring to be replaced.

- new_substring: The substring to replace the occurrences of old_substring.


Example:

SELECT REPLACE('hello world', 'world', 'universe') AS replaced_string;


This will return 'hello universe', indicating that all occurrences of the substring 'world' have been replaced with 'universe' in the original string 'hello world'.

No comments:

Post a Comment

Please provide your feedback in the comments section above. Please don't forget to follow.