LENGTH in Teradata


It is used to count the characters in the string

Input: string
Output: number of characters in the given string

Syntax:
SELECT LENGTH(string)


Example:
SELECT LENGTH('Teradata')

Result:  8. 


Note: The string must be enclosed in single quotes.

Specialty of LENGTH command:

The command will put automatically TRIM over the string that is supplied to it.
Since it uses the TRIM command, TRIM’s properties are applicable here
(i.e Trimming only the trailing spaces and not intermediate)
Length command over integers will not serve proper output.


Few ForgetCode examples:

SELECT LENGTH('Teradata  ')

Result:  8. 


SELECT LENGTH('Teradata is')

Result:  11   // (The space is counted here). 


SELECT LENGTH(6)

Result:  4   // (Undesired output). 


..