SQL Tutorial SQL Advanced SQL Database SQL References

Oracle LTRIM() Function



The Oracle (PL/SQL) LTRIM() function removes all specified characters from the left-hand side of a string.

Syntax

LTRIM(string, trim_character)

Parameters

string Required. Specify the string to trim from the left-hand side.
trim_character Optional. Specify the characters to be trimmed from string. If omitted, spaces will be removed.

Return Value

Returns the trimmed version of the specified string.

Example 1:

The example below shows the usage of LTRIM() function.

LTRIM('  SQL Tutorial')
Result: 'SQL Tutorial'

LTRIM('  SQL Tutorial    ')
Result: 'SQL Tutorial    '

LTRIM('  Learning  SQL  is  fun.')
Result: 'Learning  SQL  is  fun.'

LTRIM('  Learning  SQL  is  fun.    ')
Result: 'Learning  SQL  is  fun.    '

LTRIM('xxzyTRIM', 'xyz')
Result: 'TRIM'

Example 2:

Consider a database table called Employee. When the following INSERT statements are executed, the Name column will contain records with leading spaces.

INSERT INTO Employee VALUES ('        John', 'London', 3000);
INSERT INTO Employee VALUES ('        Marry', 'New York', 2750);
INSERT INTO Employee VALUES ('      Jo', 'Paris', 2800);
INSERT INTO Employee VALUES ('      Kim', 'Amsterdam', 3100);

-- see the result
SELECT * FROM Employee;

The query will produce the following result:

NameCitySalary
        JohnLondon3000
        MarryNew York2750
      JoParis2800
      KimAmsterdam3100

To remove the leading spaces from the Name column of the Employee table, the following query can be used:

UPDATE Employee SET Name = LTRIM(Name);

-- see the result
SELECT * FROM Employee;

This will produce the following result:

NameCitySalary
JohnLondon3000
MarryNew York2750
JoParis2800
KimAmsterdam3100

❮ Oracle Functions