Trimming a character in a string in Teradata

You can trim/remove a character in a string also using the TRIM function in Teradata.
The following examples show different ways of trimming the characters.

1. Trimming the first character in a string
SELECT TRIM(LEADING 'a' FROM 'asdfas  ')||'a'

Output:
sdfasa


2. Trimming the last character in a string
SELECT TRIM(TRAILING 'a' FROM 'asdfasa')

Output:
asdfas


Note:
Here you can only remove the first and last characters.

Interesting about TRIM:

What will be the output of
SELECT TRIM(LEADING 'a' FROM 'aaaaaaaaaaaaasdfasa')
SELECT TRIM(TRAILING 'a' FROM 'aasdfasaaaaaaaaaaaa')


Output:
sdfasa
aasdfas

TRIM will continuously look for the character at initial or trailing position for trimming until it reaches the other character.

3. To TRIM both trailing and leading 'a' BOTH clause can be used
SELECT TRIM(BOTH 'a' FROM 'aaaaaaaaaaaaasdfasa')

Output:
sdfas