The correct order is original string, string to find, then replacement string.
If REPLACE('hello world', 'x', 'y') is run, what is the output?
Aerror
Bhello yorld
Chello worly
Dhello world
✗ Incorrect
Since 'x' is not found, the original string is returned unchanged.
Does REPLACE function modify the original data in the database?
ANo, it only returns a modified string without changing stored data
BYes, it updates the stored data automatically
CYes, but only if used with UPDATE statement
DNo, it deletes the original data
✗ 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?
ASUBSTRING
BCONCAT
CREPLACE
DTRIM
✗ 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.
Practice
(1/5)
1. What does the SQL REPLACE function do?
easy
A. It converts all characters in a string to uppercase.
B. It deletes a substring from a string without replacement.
C. It extracts a substring from a string based on position.
D. It replaces all occurrences of a specified substring within a string with another substring.
Solution
Step 1: Understand the purpose of REPLACE
The REPLACE function is designed to find all instances of a substring in a string and swap them with another substring.
Step 2: Compare with other string functions
Unlike deleting or extracting substrings, REPLACE changes the content by substitution.
Final Answer:
It replaces all occurrences of a specified substring within a string with another substring. -> Option D
Quick Check:
REPLACE swaps substrings = A [OK]
Hint: REPLACE swaps all target text with new text [OK]
Common Mistakes:
Thinking REPLACE deletes text without substitution
Confusing REPLACE with substring extraction
Assuming REPLACE changes case of text
2. Which of the following is the correct syntax for the SQL REPLACE function?
easy
A. REPLACE(string, old_substring, new_substring)
B. REPLACE(old_substring, new_substring, string)
C. REPLACE(string, new_substring, old_substring)
D. REPLACE(new_substring, string, old_substring)
Solution
Step 1: Recall REPLACE function parameter order
The correct order is the original string first, then the substring to replace, then the new substring.
Step 2: Verify each option
Only REPLACE(string, old_substring, new_substring) follows the correct order: REPLACE(string, old_substring, new_substring).
Final Answer:
REPLACE(string, old_substring, new_substring) -> Option A
Quick Check:
Correct parameter order = D [OK]
Hint: Remember: original string first, then old, then new substring [OK]
Common Mistakes:
Swapping old and new substring positions
Putting new substring before old substring
Confusing parameter order
3. Given the SQL query: SELECT REPLACE('banana', 'a', 'o'); What is the output?
medium
A. 'bnn'
B. 'banana'
C. 'bonono'
D. 'banano'
Solution
Step 1: Identify the string and substrings
The original string is 'banana'. We replace all 'a' with 'o'.
Step 2: Replace all 'a' with 'o'
Replacing each 'a' in 'banana' results in 'bonono'.
Final Answer:
'bonono' -> Option C
Quick Check:
All 'a' replaced by 'o' = 'bonono' [OK]
Hint: Replace every target letter, not just first [OK]
Common Mistakes:
Replacing only first occurrence
Not replacing any character
Removing characters instead of replacing
4. What is wrong with this SQL query? SELECT REPLACE('hello world', 'l');
medium
A. It is missing the new substring to replace with.
B. The string to search in is missing.
C. The REPLACE function cannot be used in SELECT statements.
D. The function should be written as REPLACE('l', 'hello world').
Solution
Step 1: Check REPLACE function parameters
REPLACE requires three parameters: original string, old substring, new substring.
Step 2: Identify missing parameter
The query only has two parameters: original string and old substring. The new substring is missing.
Final Answer:
It is missing the new substring to replace with. -> Option A
Quick Check:
Missing third parameter = A [OK]
Hint: REPLACE needs 3 parameters: string, old, new [OK]
Common Mistakes:
Using only two parameters
Swapping parameter order
Assuming REPLACE works with one substring only
5. You have a table products with a column description containing the text 'color' spelled as 'colour' in some rows. Which SQL query correctly updates all 'colour' to 'color' in the description column?
hard
A. UPDATE products SET description = REPLACE('colour', 'color', description);
B. UPDATE products SET description = REPLACE(description, 'colour', 'color');
C. UPDATE products SET description = REPLACE(description, 'color', 'colour');
D. UPDATE products SET description = REPLACE(description, 'colour');
Solution
Step 1: Understand the goal
We want to replace all occurrences of 'colour' with 'color' in the description column.
Step 2: Check each query's correctness
UPDATE products SET description = REPLACE(description, 'colour', 'color'); correctly uses REPLACE with the column first, then old substring 'colour', then new substring 'color'. UPDATE products SET description = REPLACE('colour', 'color', description); has wrong parameter order. UPDATE products SET description = REPLACE(description, 'color', 'colour'); replaces 'color' with 'colour' (opposite). UPDATE products SET description = REPLACE(description, 'colour'); misses the new substring parameter.
Final Answer:
UPDATE products SET description = REPLACE(description, 'colour', 'color'); -> Option B
Quick Check:
Correct update syntax with REPLACE = B [OK]
Hint: Use REPLACE(column, old, new) in UPDATE to fix text [OK]
Common Mistakes:
Swapping old and new substrings
Missing new substring parameter
Using wrong parameter order
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.