Returns the number of bytes contained in the specified byte string.
Syntax element …
the byte string for which the number of bytes is to be returned.
This is a Teradata extension to the ANSI SQL:2011 standard.
The data types of byte_expression are restricted to the following:
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)
The result is as follows: