SQL REPLACE Function: Syntax & Usage
The REPLACE function in SQL is used to replace a specified substring within a string. It replaces one or more specified substrings in the source string with a new string and returns the resulting replaced string.
The syntax of the REPLACE function is:
REPLACE(string, find_string, replace_with)
In this case, string is the original string to be replaced, find_string is the substring to be replaced, and replace_with is the new string after replacement.
For example, use the REPLACE function to replace “apple” with “orange” in the string.
SELECT REPLACE('I have an apple', 'apple', 'orange');
The output is “I have an orange.”
The REPLACE function can be used in a query to replace strings, such as updating a value in a column of a table, or returning the replaced result in a SELECT statement.