I am going to continue my series of very short articles or tidbits on Transaction SQL string functions. I will exploring the LEN() function today.
The LEN() function takes one string argument as input and returns one integer argument, the size of the input string, as output
The following example determines the title length of a favorite movie of mine.
1 2 |
-- My favorite movie title returns a size of 12 select len('wizard of oz') as str_size |
1 2 3 4 5 |
output: str_size ----------- 12 |
One thing to always worry about when using TSQL functions is how will it react with a UNKNOWN or NULL values?
1 2 3 |
-- Null returns Null select len(NULL) as str_size </span> |
1 2 3 4 5 |
output: str_size ----------- NULL |
Last but not least, the empty string may return interesting results. In our case, the length of a empty string is zero.
1 2 |
-- Empty string returns 0 select len('') as str_size |
1 2 3 4 5 |
output: str_size ----------- 0 |
Next time, I will be exploring the LOWER() function.