Home / SQL / Reference / Text functions

SQL REPLACE

Replace every occurrence of some text.

Syntax

REPLACE(text, find, replace_with)

Example

Query (on the shop database used in the SQL course)

SELECT name, REPLACE(name, ' ', '_') AS slug
FROM products
LIMIT 4;

Result

nameslug
Wireless mouseWireless_mouse
Mechanical keyboardMechanical_keyboard
USB-C hubUSB-C_hub
27-inch monitor27-inch_monitor

4 rows

Related

Learn it step by step in the free lesson Functions: Text, Numbers, Dates & CASE, with exercises that check your queries.