Syntax
{ CHAR_LENGTH | CHARACTER_LENGTH } ( <string value expression> [ USING <char length units> ] ) |
OCTET_LENGTH ( <string value expression> ) |
Notes
♦ | CHAR_LENGTH and CHARACTER_LENGTH are equivalent functions that return the number of characters or bytes in a character string according to the implicit or explicit char length unit, or the number of bytes in a binary string. |
♦ | The USING clause shall only be specified if the argument is a UNICODE character string. CHARACTERS is implicit if a char length unit is not specified. |
♦ | The OCTET_LENGTH function returns the number of octets (bytes) in a character or binary string. |
♦ | The data type of the result is INTEGER. |
♦ | If the argument is null, then the result is null. |
Examples
1) | The following example selects students who have a longer last name than first name: |
SELECT firstName, lastName
FROM students
WHERE CHAR_LENGTH( lastName ) > CHARACTER_LENGTH( firstName )
2) | In the following example, the CHAR_LENGTH function returns 5 with the CHARACTERS char length unit implicitly specified: |
SELECT CHAR_LENGTH( N'Grace' )
FROM #dummy
3) | In the following example, the CHAR_LENGTH function returns 10 with the OCTETS char length unit explicitly specified: |
SELECT CHAR_LENGTH( N'Grace' USING OCTETS )
FROM #dummy
Conformance
SQL:2003 standard |
- |
Core SQL |