Return the number of characters in the input string (alias of CHAR_LENGTH).
CHARACTER_LENGTH(str)
## Overview Returns the number of characters in the input string. CHARACTER_LENGTH is the full SQL-standard spelling of CHAR_LENGTH and is functionally identical to both CHAR_LENGTH and LENGTH on string inputs. Multi-byte UTF-8 characters count as one character each. This function exists for portability with SQL-standard code. In new code, CHAR_LENGTH and LENGTH are shorter equivalents. ## Behavior - Returns NULL when the input is NULL. - Returns 0 for an empty string. - Each Unicode code point counts as one character. - Combining sequences count as the number of code points, not grapheme clusters. - Trailing whitespace is counted; it is not trimmed implicitly. - Identical to CHAR_LENGTH and LENGTH for VARCHAR and CHAR inputs. ## Compatibility - Fully conforms to the SQL standard CHARACTER_LENGTH definition. - Interchangeable with CHAR_LENGTH.
| Name | Type | Description |
|---|---|---|
str | Specifies the input string whose character count is returned. |
-- Basic length
SELECT CHARACTER_LENGTH('hello'); -- 5
-- Empty string
SELECT CHARACTER_LENGTH(''); -- 0
-- Multi-byte characters count as one
SELECT CHARACTER_LENGTH('üöä'); -- 3
-- NULL propagates
SELECT CHARACTER_LENGTH(CAST(NULL AS VARCHAR)); -- NULL
-- Trailing spaces are counted
SELECT CHARACTER_LENGTH('abc '); -- 6
-- Use in a constraint-style check
SELECT order_id
FROM retail.sales.orders
WHERE CHARACTER_LENGTH(reference_code) <> 10;