0
0
SQLquery~5 mins

SUBSTRING extraction in SQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the SQL function SUBSTRING() do?
It extracts a part of a string starting from a specified position for a specified length.
Click to reveal answer
beginner
Write the syntax of the SUBSTRING() function in SQL.
SUBSTRING(string, start_position, length) where string is the text, start_position is where to start, and length is how many characters to take.
Click to reveal answer
beginner
If you run SUBSTRING('Hello World', 7, 5), what is the output?
The output is 'World' because it starts at position 7 and takes 5 characters.
Click to reveal answer
intermediate
What happens if the length in SUBSTRING() is longer than the remaining string?
SQL returns all characters from the start position to the end of the string without error.
Click to reveal answer
intermediate
Can SUBSTRING() start extracting from a position beyond the string length?
No, if the start position is beyond the string length, the result is an empty string.
Click to reveal answer
What does SUBSTRING('Database', 3, 4) return?
A'abat'
Btaba'
C'taba
D'taba'
If you want to extract the first 5 characters of a string, which is correct?
ASUBSTRING(string, 1, 5)
BSUBSTRING(string, 5, 1)
CSUBSTRING(string, 0, 5)
DSUBSTRING(string, 1)
What will SUBSTRING('Hello', 10, 3) return?
A'lo'
B'Hel'
CEmpty string
DError
Which part of the string does SUBSTRING('Example', 4, 10) extract?
A'Exam'
B'mple'
C'ple'
D'Example'
What is the starting index for SUBSTRING() in SQL?
A1
B0
C-1
DDepends on the database
Explain how the SUBSTRING function works in SQL with an example.
Think about how you cut a piece from a longer string.
You got /4 concepts.
    What happens if the length parameter in SUBSTRING is longer than the remaining string?
    Imagine cutting more than what is left on a rope.
    You got /3 concepts.