Watch the 7.3 Webinar On-Demand
This new release brings updates to Universal Storage, query
optimization, and usability that you won’t want to miss.
Returns the byte length of a given string, array, or binary object.
LENGTH (expr)
Integer
SELECT CHARACTER_LENGTH('olé'), LENGTH('olé');
****
+--------------------------+----------------+
| CHARACTER_LENGTH('olé') | LENGTH('olé') |
+--------------------------+----------------+
| 3 | 4 |
+--------------------------+----------------+
The CHARACTER_LENGTH function returns the number of characters in the string, while the LENGTH() function returns the number of bytes in the string.
DELIMITER //
CREATE OR REPLACE FUNCTION get_length() RETURNS INT AS
DECLARE
a ARRAY(VARCHAR(30));
BEGIN
a = ['SAM','JOE','TRUDY'];
RETURN LENGTH(a);
END //
DELIMITER ;
SELECT get_length() AS "LENGTH";
****
+--------+
| LENGTH |
+--------+
| 3 |
+--------+