A  B  C  D  E  F  G  H  I  J  K  L  M  N  O  P  Q  R  S  T  U  V  W  X  Y  Z  special characters  sybase-tech-blog


Category: ASE: Functions: String Functions

len()

The String Function len() returns, like the string function char_length(), the number of characters in a string, no including blanks that might exist at the end of the string. The function len() does not return the number of bytes of that string. len() is a T-SQL extension, which can be executed by any user.

Syntax of the String Function len()

    len( string_expression)
    

The Parameter of the String Function len()

"string_expression"
The parameter "string expression" is the string to be evaluated. The parameter must be set in single or double quotes. It can consist of column names, variables or constants and must be of one of the datatypes char, nchar, varchar, nvarchar or of a datatype which can be converted into one of the required datatypes using implicit conversion If the value of the parameter "string_expression" is a NULL-value, the return value will also be NULL.

Example for the String Function len()

    select len(name), name from master..syslogins
go
name
----------- ------------------------------
5 probe
2 sa

Returns the names of all server logins and their respective length.

    select len(suid) from master..syslogins
go
Function CHAR_LENGTH invoked with wrong number or type of argument(s).

Returns an error message, because the value of the parameter "string expression" is of datatype int and therefore no valid datatpye for this function. An interesting observation is that the error message references the function char_length() and not the function len().

See also:

ASE T-SQL - Aggregate Functions,
ascii(),
char(),
char(n),
charindex(),
char_length(),
compare(),
difference(),
lower(),
ltrim(),
patindex(),
replicate(),
reverse(),
right(),
rtrim(),
sortkey(),
soundex(),
space(),
str(),
String Functions,
stuff(),
substring(),
to_unichar(),
uhighsurr(),
ulowsurr(),
upper(),
uscalar().