- Categories:
String & binary functions (General)
LENGTH, LEN¶
Returns the length of an input string or binary value. For strings, the length is the number of characters, and UTF-8 characters are counted as a single character. For binary, the length is the number of bytes.
Syntax¶
Arguments¶
expressionThe input expression must be a string or binary value.
Returns¶
The returned data type is INTEGER (more precisely, NUMBER(18, 0)).
Collation details¶
No impact. In languages in which one character is one letter and vice versa, the LENGTH function behaves the same with and without collation.
In languages where the alphabet contains digraphs or trigraphs (such as “Dz” and “Dzs” in Hungarian), each character in each digraph and trigraph is treated as an independent character, not as part of a single multi-character letter. For example, although Hungarian treats “dz” as a single letter, Snowflake returns
2forLENGTH(COLLATE('dz', 'hu')).
Examples¶
Create a table and insert VARCHAR values:
Query the table using the LENGTH function:
For the next example, create a table and insert BINARY data:
Query the table using the LENGTH function: