Get Character Length in Apache Impala

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s