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: System Functions

datalength()

The system function datalength() returns the actual length of a string or a column of a table in bytes. The function can be executed by any user. To determine the defined length of a column, the function col_length() can be used.

The system function datalength() is a Transact-SQL extension and is helpful for determining the length of values in varchar, univarchar, varbinary, text and image datatypes, because these datatypes can store values of variable length and the difference to the defined column length is not filled with blanks. If the datatypes char and unichar allow Null values per definition, these will be stored internally as varchar or univarchar. If the function datalength is executed on columns containing NULL values, the return value is also NULL.

Syntax of the System Function datalength()

    datalength (expression)
    

The parameters of the System Function datalength()

expression is a placeholder for a column, variable or constant. The datatype of expression is not relevant. Normally, expression is a column name. If a string constant is used, the expression must be set in single or double quotes.

Example for the System Function datalength()

    select name, datalength("name") from
    master..sysdatabases where name = "master"
go
name
------------------------------ -----------
master 6

Returns the actual length (6) of the value "master" in the column "name".

    select datalength("Adaptive Server")
go
-----
15

Returns the actual length (15) of the string constant "Adaptive Server".

See also:

ASE T-SQL - Aggregate Functions,
audit_event_name(),
col_length(),
col_name(),
curunreservedpgs(),
datachange(),
data_pages(),
data_pgs(),
db_id(),
db_name(),
host_id(),
host_name(),
identity(),
index_col(),
index_colorder(),
isnull(),
lct_admin(),
license_enabled(),
lockscheme(),
next_identity(),
object_id(),
object_name(),
pagesize(),
pointer_size(),
ptn_data_pgs(),
reserved_pages(),
reserved_pgs(),
rowcnt(),
row_count(),
showplan_in_xml(),
syb_sendmsg(),
syb_sendmsg(),
System Functions,
tempdb_id(),
tran_dumpable_status(),
tsequal(),
used_pages(),
used_pgs().