Skip to main content

This is documentation for Caché & Ensemble.

For information on converting to InterSystems IRIS, see the InterSystems IRIS Adoption Guide and the InterSystems IRIS In-Place Conversion Guide, both available on the WRC Distributions page (login required).

Previous sectionNext section


A string function that returns a string with the leading blanks removed.



{fn LTRIM(string-expression)}


Argument Description
string-expression A string expression, which can be the name of a column, a string literal, or the result of another scalar function, where the underlying data type can be represented as any character type (such as CHAR or VARCHAR).


LTRIM removes the leading blanks from a string expression, and returns the string as type VARCHAR. If string-expression is NULL, LTRIM returns NULL. If string-expression is a string consisting entirely of blank spaces, LTRIM returns the empty string ('').

LTRIM leave trailing blanks; to remove trailing blanks, use RTRIM. To remove leading and/or trailing characters of any type, use TRIM. To pad a string with leading blanks or other characters, use LPAD. To create a string of blanks, use SPACE.

Note that LTRIM can be used as an ODBC scalar function (with the curly brace syntax) or as an SQL general function.


The following Embedded SQL example removes the five leading blanks from the string. It leaves the five trailing blanks:

   SET a="     Test string with 5 leading and 5 trailing spaces.     "
   &sql(SELECT {fn LTRIM(:a)} INTO :b)
   IF SQLCODE'=0 {
     WRITE !,"Error code ",SQLCODE }
   ELSE {
     WRITE !,"Before LTRIM",!,"start:",a,":end"
     WRITE !,"After LTRIM",!,"start:",b,":end" }
Copy code to clipboard


Before LTRIM
start:     Test string with 5 leading and 5 trailing spaces.     :end
start:Test string with 5 leading and 5 trailing spaces.     :end

See Also


FeedbackOpens in a new window