Skip to main contentSkip to solution

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.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question