15.00 - BYTES - Teradata Database

Teradata Database SQL Functions, Operators, Expressions, and Predicates

Teradata Database
Release Number
Content Type
Programming Reference
Publication ID
English (United States)
Last Update



Returns the number of bytes contained in the specified byte string.




Syntax element …

Specifies …


the byte string for which the number of bytes is to be returned.

ANSI Compliance

This is a Teradata extension to the ANSI SQL:2011 standard.

Argument Types

The data types of byte_expression are restricted to the following:

  • UDT that has an implicit cast to a predefined byte type
  • To define an implicit cast for a UDT, use the CREATE CAST statement and specify the AS ASSIGNMENT clause. For more information on CREATE CAST, see SQL Data Definition Language.

    Implicit type conversion of UDTs for system operators and functions, including BYTES, is a Teradata extension to the ANSI SQL standard. To disable this extension, set the DisableUDTImplCastForSysFuncOp field of the DBS Control Record to TRUE. For details, see Utilities: Volume 1 (A-K).

    For more information on implicit type conversion of UDTs, see Chapter 13: “Data Type Conversions.”

    Length Includes Trailing Zeros

    Because trailing double zero bytes are considered bytes, the length of the value in a fixed length column is always equal to the length defined for the column.

    The length of the value in a variable length column is always equal to the number of bytes, including any trailing double zero bytes, contained in that value.

    If you do not want trailing blanks included in the byte count for a data value, use the TRIM function on the argument to BYTES. For example:

       SELECT BYTES( TRIM( TRAILING FROM byte_col ) ) FROM table1;

    For more information on TRIM, see “TRIM” on page 1270.


    The following statement applies the BYTES function to the BadgePic column, which is type VARBYTE(32000), to obtain the number of bytes in each badge picture.

       SELECT BadgePic, BYTES(BadgePic) 
       FROM Employee; 

    The result is as follows:

       BadgePic        Bytes(BadgePic)
       --------------  ---------------
       20003BA0                      4
       9A3243F805                    5
       EEFF08C3441900                7