Apart from the LENGTH() function, CHAR_LENGTH function can also be used to get the length of a string. Both leading and trailing spaces at the begin and end of the string is included when calculating the length. Both functions do the same purpose. These functions accept characters as input and return an INT value. Since numbers will not be accepted as input, any numerical input must be enclosed in single quotes in order to be regarded as a string.
Syntax: LENGTH(String)
Syntax: CHAR_LENGTH(String)
SELECT LENGTH(‘ This is a test ‘);
Returns 17 including leading and trailing spaces.
SELECT CHAR_LENGTH(‘ This is a test ‘);
Returns 17 including leading and trailing spaces.
Hope you find this article informative.
Please subscribe for more interesting updates.
2 comments