The REPLACE function in SQL is used to replace all given substrings with another substring in a text or string. Can be used for basic replacement, conditional replacement, and NULL value handling. The basic syntax is: REPLACE(string, old_substring, new_substring).
Usage of REPLACE function in SQL
The REPLACE function is used to replace all given values in a text or string. A given substring is another substring. It can update data in the database based on specified conditions.
Syntax
REPLACE(string, old_substring, new_substring)
Parameters
Usage
SELECT REPLACE('This is a sample text', 'sample', 'example');
Result: This is an example text
SELECT REPLACE('This is a sample text', 'sample', 'example', 1);
Result: This is an example text
where 1 specifies that only the first occurrence of the substring is replaced.
SELECT REPLACE('This is a sample text', NULL, 'example');
Result: NULL
Notes
The above is the detailed content of How to use replace function in sql. For more information, please follow other related articles on the PHP Chinese website!