Recall & Review
beginner
What does the TRIM function do in SQL?
TRIM removes spaces or specified characters from both the beginning and the end of a string.
Click to reveal answer
beginner
How does LTRIM differ from RTRIM?
LTRIM removes spaces or specified characters only from the start (left side) of a string, while RTRIM removes them only from the end (right side).
Click to reveal answer
beginner
Write a SQL query to remove spaces from the left side of the string ' hello '.
SELECT LTRIM(' hello '); -- Result: 'hello '
Click to reveal answer
beginner
Why would you use TRIM functions in a database?
To clean data by removing unwanted spaces or characters that can cause errors or mismatches in searches and comparisons.
Click to reveal answer
intermediate
Can TRIM remove characters other than spaces? How?
Yes, by specifying the character to remove inside the TRIM function, for example: TRIM('x' FROM 'xxhelloxx') returns 'hello'.
Click to reveal answer
What does RTRIM('hello ') return?
✗ Incorrect
RTRIM removes spaces from the right side, so trailing spaces after 'hello' are removed.
Which function removes spaces only from the left side of a string?
✗ Incorrect
LTRIM removes spaces from the left side only.
How do you remove the character 'x' from both ends of 'xxhelloxx'?
✗ Incorrect
TRIM with 'x' removes 'x' characters from both ends.
What will TRIM(' hello ') return?
✗ Incorrect
TRIM removes spaces from both ends, leaving 'hello'.
If you want to remove spaces only from the right side of a string, which function do you use?
✗ Incorrect
RTRIM removes spaces from the right side only.
Explain the difference between TRIM, LTRIM, and RTRIM functions in SQL.
Think about which side of the string each function cleans.
You got /3 concepts.
Describe a real-life situation where using TRIM functions would help clean data.
Imagine typing a name with spaces by mistake.
You got /3 concepts.