SQL/MP Reference Manual
HP NonStop SQL/MP Reference Manual—523352-013
C-20
CHAR_LENGTH Function
CHAR_LENGTH Function
The CHAR_LENGTH function returns the number of characters in a string.
character-string
specifies the string for which the length is to be returned.
Considerations—CHAR_LENGTH Function
SQL returns the result as a two-byte signed integer with a scale of zero.
If character-string is a null value, SQL returns a length of null.
For a column declared as a fixed CHAR, SQL returns the maximum length of that
column. For a VARCHAR column, SQL returns the actual length of the string
stored in that column.
The OCTET_LENGTH and CHAR_LENGTH functions are similar. The
OCTET_LENGTH function returns the number of bytes in the string. The result of
both functions is the same for single-byte character data types. For a multi byte
character data type, the two functions return different results.
Examples—CHAR_LENGTH Function
This example returns 12:
CHAR_LENGTH ( "Robert" || " " || "Smith" )
This example returns zero:
CHARACTER_LENGTH ( "" )
This example returns the value 3:
CHAR_LENGTH ( _KANJI "abcdef")
These two examples use a table created:
CREATE TABLE EMPLOYEE (EMPNAME CHAR(20),
ADDRESS VARCHAR(100));
INSERT INTO EMPLOYEE VALUES ("Robert Smith",
"19333 Vallco Parkway ");
CHAR[ACTER]_LENGTH ( character-string )
where character-string is:
{ string-literal }
{ column-name }
{ param-name }
{ host-var-name }
{ UPSHIFT function }
{ character-expression }