|
char_length()
The
string function
char_length()
returns an
integer
value
. The return value corresponds to the character length of the value given in the parameter "char_expression" or "uchar_expression".
If one of the parameters is a
table
column
with variable datatype lengths, the length of the content of the column is returned. Is the column a fixed length column, possible spaces are not removed but added to the overall length of the value found.
Please note that the number of characters of a
multibyte character sets
is mostly smaller than the number of
bytes. To determine the number of bytes the
system function
datalength()
should be used. If the parameter "char_expression" or "uchar_expression" is
NULL
the return value is also NULL.
Syntax of the string function char_length()
char_length([char_expression | uchar_expression])
The parameters of the string function char_length()
char_expression
The parameter "char_expression" can either be a column name,
a constant,
a variable
or
an expression
. The values can be of one of these
datatypes:
char,
varchar,
nchar
or
nvarchar
.
uchar_expression
The parameter "uchar_expression" can either be a column name, a constant,
a variable or an expressions. The values can be of one of these
datatypes
unichar
or
univarchar
.
Example for the string function char_length()
select char_length("1234567")
go
-----
7
Returns "7".
select char_length("abcdefg")
go
-----
7
Returns "7".
select char_length(column_name)
from table_name
where column_name = abcdefg
go
-----
7
Returns "7".
select max(char_length(column_name))
from table_name
go
-----
104
Returns 104, the content of the column with the longest character string.
See also:
ASE T-SQL - Aggregate Functions, ascii(), char(), char(n), charindex(), compare(), difference(), lower(), ltrim(), patindex(), replicate(), reverse(), right(), rtrim(), sortkey(), soundex(), space(), str(), String Functions, stuff(), substring(), to_unichar(), uhighsurr(), ulowsurr(), upper(), uscalar().
|