0
0
MySQLquery~5 mins

REPLACE function in MySQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the REPLACE function do in MySQL?
The REPLACE function searches for all occurrences of a substring in a string and replaces them with another substring.
Click to reveal answer
beginner
Syntax of the REPLACE function in MySQL?
REPLACE(original_string, from_substring, to_substring) - It returns a new string where all occurrences of from_substring are replaced by to_substring.
Click to reveal answer
beginner
What happens if the substring to replace is not found in the original string?
The REPLACE function returns the original string unchanged if the substring to replace is not found.
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 replace multiple occurrences of the substring?
Yes, REPLACE replaces all occurrences of the substring in the original string, not just the first one.
Click to reveal answer
What does REPLACE('hello world', 'world', 'there') return?
A'there world'
B'hello world'
C'hello there'
D'hello'
If the substring to replace is not found, what does REPLACE return?
AOriginal string unchanged
BEmpty string
CNULL
DAn error
Which of these is the correct syntax for REPLACE?
AREPLACE(string, old_substring, new_substring)
BREPLACE(old_substring, new_substring, string)
CREPLACE(string, new_substring, old_substring)
DREPLACE(new_substring, string, old_substring)
What will REPLACE('banana', 'a', 'o') return?
Abanana
Bbano
Cbnn
Dbonono
Can REPLACE be used to remove a substring by replacing it with an empty string?
AOnly if substring is at the start
BYes
CNo
DOnly if substring is at the end
Explain how the REPLACE function works in MySQL and give a simple example.
Think about changing parts of a word to another word.
You got /4 concepts.
    Describe what happens if the substring to replace does not exist in the original string when using REPLACE.
    What if you try to replace something that isn't there?
    You got /3 concepts.