Challenge - 5 Problems
REPLACE Function Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate1:30remaining
What is the output of this REPLACE function query?
Given the string 'hello world', what will be the result of this SQL query?
SELECT REPLACE('hello world', 'world', 'SQL') AS result;SQL
SELECT REPLACE('hello world', 'world', 'SQL') AS result;
Attempts:
2 left
💡 Hint
REPLACE changes all occurrences of the second string with the third string inside the first string.
✗ Incorrect
The REPLACE function looks for 'world' in 'hello world' and replaces it with 'SQL', resulting in 'hello SQL'.
❓ query_result
intermediate1:30remaining
What does this REPLACE query return?
What is the output of this SQL query?
SELECT REPLACE('banana', 'a', 'o') AS result;SQL
SELECT REPLACE('banana', 'a', 'o') AS result;
Attempts:
2 left
💡 Hint
Every 'a' in 'banana' is replaced by 'o'.
✗ Incorrect
The REPLACE function replaces all 'a' characters with 'o', so 'banana' becomes 'bonono'.
📝 Syntax
advanced1:30remaining
Which query will cause a syntax error?
Identify which of these SQL queries using REPLACE will cause a syntax error.
Attempts:
2 left
💡 Hint
REPLACE requires exactly three arguments: the string, the substring to find, and the substring to replace with.
✗ Incorrect
Option B has only two arguments, which is invalid syntax for REPLACE. Options A and B are correct syntax. Option B has too many arguments and will also cause an error, but the question asks for one correct answer causing syntax error, and D is the invalid with missing argument.
🔧 Debug
advanced2:00remaining
Why does this REPLACE query return the original string?
Consider this query:
Why does it return 'apple' unchanged?
SELECT REPLACE('apple', 'b', 'c') AS result;Why does it return 'apple' unchanged?
SQL
SELECT REPLACE('apple', 'b', 'c') AS result;
Attempts:
2 left
💡 Hint
Think about what happens if the substring to replace is not found.
✗ Incorrect
If the substring to replace is not found in the original string, REPLACE returns the original string unchanged.
🧠 Conceptual
expert2:00remaining
How many replacements occur in this query?
Given the string 'abracadabra', how many characters will be replaced by this query?
SELECT REPLACE('abracadabra', 'a', 'x') AS result;SQL
SELECT REPLACE('abracadabra', 'a', 'x') AS result;
Attempts:
2 left
💡 Hint
Count how many times 'a' appears in 'abracadabra'.
✗ Incorrect
'abracadabra' contains 5 'a' characters, so 5 replacements occur.