Previous Next JavaScript must be enabled to correctly display this content

## trim function

The `trim` function enables you to trim leading or trailing characters (or both) from a string. The `ltrim` function enables you to trim leading characters from a string. The `rtrim` function enables you to trim trailing characters from a string.

    returnvalue trim(source [, position [, trim_character]])

    source ::= any*
    position ::= "leading"|"trailing"|"both"
    trim_character ::= string*
    returnvalue ::= string

    returnvalue ltrim(source)

    returnvalue rtrim(source)
    source ::= any*
    returnvalue ::= string

Example: Remove leading and trailing blank spaces from the route details of the passenger whose ticket number is 1762350390409.

    SELECT trim(bag.baginfo[0].routing,"trailing"," ")
    FROM BaggageInfo bag
    WHERE ticketNo=1762376407826

Output:

    {"Column_1":"JFK/MAD"}

Using `ltrim` function to remove leading spaces:

    SELECT ltrim(bag.baginfo[0].routing)
    FROM BaggageInfo bag
    WHERE ticketNo=1762376407826

Output:

    {"Column_1":"JFK/MAD"}

Using `rtrim` function to remove trailing spaces:

    SELECT rtrim(bag.baginfo[0].routing)
    FROM BaggageInfo bag
    WHERE ticketNo=1762376407826

Output:

    {"Column_1":"JFK/MAD"}