Replace Function In Sql in SQL
? REPLACE Function in SQL
The REPLACE() function in SQL is used to replace all occurrences of a substring within a string with another substring.
? Syntax:
REPLACE(string, from_substring, to_substring)string: The original string.from_substring: The substring you want to replace.to_substring: The new substring you want to insert.
? Example 1: Basic Replacement
SELECT REPLACE('SQL is fun', 'fun', 'awesome') AS result;? Output:
| result |
|---|
| SQL is awesome |
? Example 2: Remove characters (replace with empty string)
SELECT REPLACE('123-456-7890', '-', '') AS phone_number;Output:
| phone_number |
|---|
| 1234567890 |
? Example 3: Case-sensitive
SELECT REPLACE('Hello HELLO Hello', 'Hello', 'Hi') AS result;Output:
| result |
|---|
| Hi HELLO Hi |
Only replaces exact matches (case-sensitive).
? Supported in:
MySQL
PostgreSQL
SQL Server
Oracle
Would you like to see how to use REPLACE() in an UPDATE statement to modify table data?