REPLACE

SQL REPLACE function is a string function used to replace all occurrences of a substring within a given string with another substring. The syntax for the REPLACE function in SQL is as follows:

REPLACE(string, old_substring, new_substring)

where string is the original string, old_substring is the substring to be replaced, and new_substring is the replacement substring.

Example

For example, consider the following SQL statement:

SELECT REPLACE('Hello World', 'World', 'Universe');

This will return the string ‘Hello Universe’, where the substring ‘World’ has been replaced with the substring ‘Universe’.

The REPLACE function is often used in SQL queries to clean up data by replacing certain characters or substrings with others. It can also be used to modify text values in tables by updating them with the new replaced string.

One thing to note is that the REPLACE function is case sensitive by default, which means that it will only replace the occurrences of the substring with the exact same case. However, there is an optional fourth argument that can be used to specify the number of occurrences to replace.

In summary, the SQL REPLACE function is a useful tool for manipulating strings in SQL queries and can help make data cleaner and more organized.