0
0
SQLquery~5 mins

TRIM, LTRIM, RTRIM in SQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
A'olleh'
B' hello'
C'hello '
D'hello'
Which function removes spaces only from the left side of a string?
ATRIM
BLTRIM
CRTRIM
DREMOVE
How do you remove the character 'x' from both ends of 'xxhelloxx'?
ATRIM('x' FROM 'xxhelloxx')
BLTRIM('x' FROM 'xxhelloxx')
CRTRIM('x' FROM 'xxhelloxx')
DREMOVE('x', 'xxhelloxx')
What will TRIM(' hello ') return?
A'hello '
B' hello'
C'hello'
D' hello '
If you want to remove spaces only from the right side of a string, which function do you use?
ARTRIM
BLTRIM
CTRIM
DRIGHTTRIM
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.