Oracle 19c SQL

  1. Home
  2. Docs
  3. Oracle 19c SQL
  4. Single Row Character Functions
  5. LTRIM

LTRIM

  • LTRIM is a single row character function.
  • The LTRIM function removes characters from the left of a given string.
  • This function begins scanning the input text from first character and removes all characters that appear in the trim-expression until reaching a character that is not in the “trim-expression” and then returns the result.
  • Return type is VARCHAR2.

Syntax : LTRIM(Str1, trim-expression)

SELECT LTRIM('   The CodeMan', ' ') SiteName
  FROM DUAL;

SITENAME
-----------
The CodeMan
  • When 2nd parameter to LTRIM is not provided, default is empty space.
  • If “trim-expression” which is the 2nd parameter if omitted, LTRIM function will remove all leading spaces from¬†input string.
SELECT LTRIM('   The CodeMan') SiteName FROM DUAL;

SITENAME
-----------
The CodeMan
  • 2nd parameter “trim-expression” can be used to trim any character any number of times.

Following code removes all leading “*” from input string.

SELECT LTRIM('******dcodeman******', '*') SiteName 
  FROM DUAL;

SITENAME
--------------
dcodeman******
SELECT LTRIM('***$***dcodeman******', '*') SiteName 
  FROM DUAL;

SITENAME
------------------
$***dcodeman******
  • Specifying same character multiple times as “trim-expression” in the 2nd parameter does not makes sense though Oracle does not report any error.
SELECT LTRIM('***$***dcodeman****', '***') SiteName 
  FROM DUAL;

SITENAME
----------------
$***dcodeman****
  • You can remove all characters you want to remove from the beginning of the input string using LTRIM function.
  • Specify all characters at-least once in “trim-expression” that you want to remove from the beginning in the result set.

Following code removes all leading “$” and “*” from the input string until it finds a character not specified as a “trim-expression” in the 2nd parameter.

SELECT LTRIM('***$**$*#**$*dcodeman****', '*$') SiteName 
  FROM DUAL;

SITENAME
-----------------
#**$*dcodeman****
  • LTRIM can be used with NUMBER data types too. Both parameters to LTRIM can be of NUMBER data type. Returns a NUMBER when dealing with NUMBER types.
SELECT LTRIM(1113312211234121215, 123) Result 
  FROM DUAL;

RESULT
-------
4121215
Was this article helpful to you? Yes No

How can we help?