Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Concatenation
Simple text functions
How to modify strings
16. Function replace
Review

Instruction

Great! You can also replace certain parts of your string with anything you want. This is where we can use the function replace(x,y,z), which takes the string x and, if it finds the text y in the x, then y will be replaced with text z. Take a look:

SELECT replace('young man','young','old');

In the above example, the function will look for 'young' in the string 'young man' and will replace it with 'old'. As a result, we'll get 'old man'. Of course, you can provide a column name instead of 'young man' just as well.

Please note that the SQL standard does not contain the function replace we've just described. However, it's so popular among the available databases that we've decided to teach you how to use it.

Exercise

For slogan id = 1, show its original text and its text with the word 'Feel' replaced with 'Touch'. Name the second column changed_text.

Stuck? Here's a hint!

Use replace(text, 'Feel', 'Touch').