Previous Topic: The POSITION FunctionNext Topic: The COALESCE Function


The CHAR_LENGTH Function

The CHAR_LENGTH function returns the length of a character string literal or character column. For VARCHAR columns the actual used string length is returned. For CHAR columns the length of the column is returned. For literals the length of the literal is returned. If a column is NULL, NULL is returned. Output variable names for CHAR_LENGTH are shortened to simply LENGTH_n. The syntax for this function is:

CHAR_LENGTH('string'/colname)

In the following example, the TRIM function is combined with the CHAR_LENGTH function to find the used length of the column RECOV_PROC in each row. The following SQL statement returns the actual length of the data in the column for each row:

“SELECT CHAR_LENGTH(TRIM(RECOV_PROC)) FROM SYSTEMS”

The following array of variables is returned: