Recall & Review
beginner
What does the REPLACE function do in SQL?
The REPLACE function searches for all occurrences of a specified substring in a string and replaces them with another substring.
Click to reveal answer
beginner
Syntax of the REPLACE function in SQL?
REPLACE(original_string, string_to_find, string_to_replace_with)
Click to reveal answer
beginner
Example: What is the result of REPLACE('apple pie', 'pie', 'tart')?
The result is 'apple tart' because 'pie' is replaced by 'tart'.
Click to reveal answer
intermediate
Can REPLACE function change multiple occurrences in a string?
Yes, REPLACE changes all occurrences of the target substring in the original string.
Click to reveal answer
beginner
What happens if the string to find is not present in the original string?
The original string is returned unchanged because there is nothing to replace.
Click to reveal answer
What does REPLACE('banana', 'a', 'o') return?
✗ Incorrect
All 'a' characters are replaced with 'o', so 'banana' becomes 'bonono'.
Which of these is the correct syntax for REPLACE?
✗ Incorrect
The correct order is original string, string to find, then replacement string.
If REPLACE('hello world', 'x', 'y') is run, what is the output?
✗ Incorrect
Since 'x' is not found, the original string is returned unchanged.
Does REPLACE function modify the original data in the database?
✗ Incorrect
REPLACE returns a new string with replacements; it does not change stored data unless used inside an UPDATE.
Which SQL function would you use to replace text inside a string?
✗ Incorrect
REPLACE is used to substitute parts of a string with new text.
Explain how the REPLACE function works in SQL with an example.
Think about how you would change words in a sentence.
You got /4 concepts.
What happens if the substring to replace is not found in the original string when using REPLACE?
Consider what happens if you try to replace a word that isn't there.
You got /3 concepts.