datalength

Returns the actual length, in bytes, of the specified column or string.

Syntax

datalength(expression)

Parameters

Examples

Usage

  • datalength returns the uncompressed length of a large object column, even when the column is compressed.

  • For columns defined for the Unicode datatype, datalength returns the actual number of bytes of the data stored in each row. For example, this is what is returned if a unitext column ut contains row value U+0041U+0042U+d800dc00:
    select datalength(ut) from unitable
    -------------
    8
  • datalength finds the actual length of the data stored in each row. datalength is useful on varchar, univarchar, varbinary, text, and image datatypes, since these datatypes can store variable lengths (and do not store trailing blanks). When a char or unichar value is declared to allow nulls, the SAP ASE server stores it internally as varchar or univarchar. For all other datatypes, datalength reports the defined length.

  • datalength accepts the text_locator, unitext_locator, and image_locator LOB datatypes.

  • datalength of any NULL data returns NULL.

Standards

ANSI SQL – Compliance level: Transact-SQL extension.

Permissions

Any user can execute datalength.

Related reference
char_length
col_length