trim function in teradata

trim function accepts a string expression and removes the leading, trailing, or both leading and trailing white spaces. These characters might be white space characters. We have two more functions ltrim and rtrim. These two functions remove the padded characters from left and right sides, respectively.

TRIM

TRIM function accepts a string expression and removes both leading and trailing white spaces. See the syntax given below.

TRIM (TRAILING FROM STRING)
TRIM (LEADING FROM STRING)
TRIM (BOTH FROM STRING)

TRAILING

This keyword removes the white space from the end of the string.

LEADING

This keyword removes the white space from the start of the string.

BOTH

This keyword removes the white space from both the start and end of the string.

STRING

The string expression value might be obtained from the column of a table.


Suppose we have a table named 'std_name' that contains two columns 'first_name', 'last_name'. These two columns contain the following values padded with white spaces. Now, we need to remove the padded white spaces and concatenate these values.

std_name:

first_name           last_name
-------------------------------
'     Oliver '   |   '  Berners      '
		 |  		
		 |  		
		 |  		

The following statement removes the unnecessary white spaces from the values obtained from the first_name and last_name columns and returns the concatenated string.

SELECT TRIM(BOTH FROM first_name) || ', ' || TRIM(BOTH FROM last_name) FROM std_name;

The resulting expression will be:

'Oliver, Berners'

Now, what if we don't apply the TRIM function. See the SELECT statement again.

SELECT  first_name || ', ' || last_name FROM std_name;

The resulting string would be:

'     Oliver ,   Berners      '

Learn more

subtract dates in teradata

teradata INSTR function


Was this article helpful?