0
0
MySQLquery~5 mins

LOCATE and INSTR in MySQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the LOCATE function do in MySQL?
LOCATE finds the position of a substring inside a string and returns the position as a number. If the substring is not found, it returns 0.
Click to reveal answer
intermediate
How is INSTR different from LOCATE in MySQL?
INSTR also finds the position of a substring inside a string but does not accept a starting position argument. LOCATE can start searching from a specific position, INSTR always searches from the beginning.
Click to reveal answer
beginner
Write the syntax of LOCATE function.
LOCATE(substring, string, start_position) - start_position is optional and tells where to start searching.
Click to reveal answer
beginner
What will LOCATE('cat', 'concatenate') return?
It returns 4 because 'cat' starts at the 4th character in 'concatenate'.
Click to reveal answer
beginner
If INSTR('hello world', 'o') is used, what is the output?
It returns 5 because the first 'o' appears at the 5th position in 'hello world'.
Click to reveal answer
What does LOCATE('a', 'banana') return?
A0
B1
C3
D2
Which function allows specifying a start position for searching a substring?
ALOCATE
BSUBSTRING
CINSTR
DLENGTH
What does INSTR('apple', 'p') return?
A3
B2
C1
D0
If the substring is not found, what do LOCATE and INSTR return?
A0
B-1
CNULL
D1
Which of these is a valid LOCATE usage?
ALOCATE('text', 'x')
BLOCATE('x', 'text', '3')
CLOCATE('x', 'text', 3)
DLOCATE('x')
Explain how LOCATE and INSTR functions work in MySQL and when you might use each.
Think about searching inside words and starting points.
You got /5 concepts.
    Describe the difference in syntax and behavior between LOCATE and INSTR.
    Focus on argument order and optional parameters.
    You got /5 concepts.