What will be the output of the following SQL query?
SELECT LENGTH(" DELHI"), LENGTH(LTRIM(" DELHI"));
What will be the output of the following SQL query?
SELECT LENGTH(" DELHI"), LENGTH(LTRIM(" DELHI"));
Solution
✅ Correct Option: 2
LENGTH counts every character, including spaces. The string " DELHI" has 2 leading spaces and 5 letters, so LENGTH(" DELHI") is 7.
LTRIM removes the leading spaces, leaving "DELHI", so LENGTH(LTRIM(" DELHI")) is 5.
Option 1: wrongly assumes LENGTH ignores spaces.
Option 3: wrongly assumes LTRIM leaves the string unchanged.
LTRIM removes only leading spaces, RTRIM only trailing spaces, and TRIM both. None of them touches spaces in the middle of a string.
Related questions:
2025: 3 June Shift 2
2026: 24 May Shift 1
2026: 29 May Shift 2