TRIM()

Documentation

VoltDB Home » Documentation » Using VoltDB

TRIM()

TRIM() — Returns a string with leading and/or training spaces removed.

Synopsis

TRIM( [[ LEADING | TRAILING | BOTH ] [character] FROM] string-expression )

Description

The TRIM() function returns a string with leading and/or trailing spaces removed. By default, the TRIM function removes spaces from both the beginning and end of the string. If you specify the LEADING or TRAILING clause, spaces are removed from either the beginning or end of the string only.

You can also specify an alternate character to remove. By default only spaces (UTF-8 character code 32) are removed. If you specify a different character, only that character will be removed. For example, the following INSERT statement uses the TRIM function to remove any TAB characters from the beginning of the string input for the ADDRESS column:

INSERT INTO Customers (first, last, address) 
      VALUES(?, ?, 
         TRIM( LEADING CHAR(9) FROM CAST(? AS VARCHAR) ) 
      );

Example

The following example uses TRIM() to remove extraneous leading and trailing spaces from the output for three VARCHAR columns:

SELECT TRIM(first), TRIM(last), TRIM(address) FROM Customer 
      ORDER BY last, first;