Oracle LTRIM() Function

Oracle LTRIM() is a built-in function that returns a string with any specified leading characters (by default, spaces) removed.

If you need to remove characters from the right-hand side of a string, use RTRIM(); if you need to remove characters from both the left and right sides of a string, use TRIM().

Oracle LTRIM() Syntax

Here is the syntax for the Oracle LTRIM() function:

LTRIM(str [, set ])

Parameters

str

Required. It can be a value of type CHAR, VARCHAR2, NCHAR, NVARCHAR2, CLOB, or NCLOB.

set

Optional. It is the set of characters to remove. By default, it is space.

Return Value

The Oracle LTRIM() function returns a string with any specified leading characters (by default, spaces) removed.

LTRIM() scans from the beginning of str and removes all characters in set that appear until it reaches a character not in set, and then returns the result.

If any argument is NULL, LTRIM() will return NULL.

Oracle LTRIM() Examples

Here are some examples that demonstrate the usage of the Oracle LTRIM() function.

Remove whitespace

This statement demonstrates how to use the Oracle LTRIM() function to remove leading whitespace from ' Hello ':

SELECT
    '   Hello   ' Origin,
    LTRIM('   Hello   ') Result
FROM dual;

Output:

ORIGIN         RESULT
______________ ___________
   Hello       Hello

Remove specified characters

This statement demonstrates how to use the Oracle LTRIM() function to remove _*# characters from the left-hand side of '___***#Hello':

SELECT
    '___***#Hello___***#' Origin,
    LTRIM('___***#Hello___***#', '_*#') Result
FROM dual;

Output:

ORIGIN                 RESULT
______________________ _______________
___***#Hello___***#    Hello___***#

NULL arguments

If any argument is NULL, LTRIM() will return NULL.

SET NULL 'NULL';
SELECT
    LTRIM(NULL),
    LTRIM(NULL, 'ABC'),
    LTRIM('ABC', NULL)
FROM dual;

Output:

LTRIM(NULL)    LTRIM(NULL,'ABC')    LTRIM('ABC',NULL)
______________ ____________________ ____________________
NULL           NULL                 NULL

In this example, we use the SET NULL 'NULL'; statement to display NULL values as the string 'NULL'.

Conclusion

Oracle LTRIM() is a built-in function that returns a string with any specified leading characters (by default, spaces) removed.