0
0
SQLquery~20 mins

REPLACE function in SQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
REPLACE Function Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
1: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;
A'hello SQL'
B'hello world'
C'SQL world'
D'helloSQL'
Attempts:
2 left
💡 Hint
REPLACE changes all occurrences of the second string with the third string inside the first string.
query_result
intermediate
1: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;
A'bnn'
B'banana'
C'bonono'
D'banano'
Attempts:
2 left
💡 Hint
Every 'a' in 'banana' is replaced by 'o'.
📝 Syntax
advanced
1:30remaining
Which query will cause a syntax error?
Identify which of these SQL queries using REPLACE will cause a syntax error.
ASELECT REPLACE('test', 't', 'T') AS result;
BSELECT REPLACE('test', 't') AS result;
CSELECT REPLACE('test', 't', 'T', 'extra') AS result;
D;tluser SA )'T' ,'t' ,'tset'(ECALPER TCELES
Attempts:
2 left
💡 Hint
REPLACE requires exactly three arguments: the string, the substring to find, and the substring to replace with.
🔧 Debug
advanced
2:00remaining
Why does this REPLACE query return the original string?
Consider this query:

SELECT REPLACE('apple', 'b', 'c') AS result;

Why does it return 'apple' unchanged?
SQL
SELECT REPLACE('apple', 'b', 'c') AS result;
ABecause the function is case-sensitive and 'B' is different from 'b'.
BBecause REPLACE only works with numeric strings.
CBecause the third argument must be longer than the second.
DBecause 'b' is not found in 'apple', so no replacement happens.
Attempts:
2 left
💡 Hint
Think about what happens if the substring to replace is not found.
🧠 Conceptual
expert
2: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;
A5
B4
C3
D6
Attempts:
2 left
💡 Hint
Count how many times 'a' appears in 'abracadabra'.