DATA-MANAGEMENT-FOUNDATIONS practice question 14 of 15

Which function removes only the leading spaces from a string?

Full set: 60 questions

Domain Data Management Systems

Answer options
A: LTRIM Correct answer
B: LEFT
C: TRIM
D: REPLACE
Correct Answer:
A. LTRIM
Explanation

The LTRIM function is a standard SQL string function designed specifically to remove whitespace characters from the beginning (left side) of a string. It targets only the leading spaces and does not affect any characters within or at the end of the string. This directly addresses the question's requirement to remove only the leading spaces. For example, LTRIM(' Hello World ') would result in 'Hello World ', preserving the trailing spaces.

Why Incorrect

B. LEFT: This function extracts a specified number of characters from the left side of a string; it does not remove characters.
C. TRIM: By default, this function removes spaces from both the beginning (leading) and the end (trailing) of a string.
D. REPLACE: This function substitutes all occurrences of a specified substring, meaning it would remove all spaces, not just leading ones. ---

References

1. Microsoft SQL Server Documentation (Transact-SQL): "LTRIM (Transact-SQL) - Returns a character expression after it removes leading blanks."

Source: Microsoft Docs, LTRIM (Transact-SQL), SQL Server. Retrieved from https://docs.microsoft.com/en-us/sql/t-sql/functions/ltrim-transact-sql

2. Oracle Database Documentation: "LTRIM removes from the left end of char all of the characters that appear in set. If you do not specify set, then it defaults to a single blank."

Source: Oracle Help Center, Database SQL Language Reference, 19c, "LTRIM". Retrieved from https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/LTRIM.html#GUID-37469B5B-5585-4B66-A502-11D4510AF343

3. PostgreSQL Documentation: "The ltrim function removes the longest string containing only characters from characters (a space by default) from the start of string."

Source: PostgreSQL 14 Documentation, Chapter 9. Functions and Operators, Section 9.4. String Functions and Operators. Retrieved from https://www.postgresql.org/docs/current/functions-string.html

4. Stanford University Infolab: Course materials for CS145 (Introduction to Databases) often cover standard SQL functions. The TRIM family of functions (LTRIM, RTRIM) is a fundamental concept.

Source: Stanford University, CS145 Lecture Notes, "SQL - String Operations". While direct links to specific PDFs change, the curriculum consistently covers these standard functions as defined in the SQL:2011 standard. An example can be seen in publicly available slides and exercises.

Scroll to Top