15.00 - FROM_BYTES - Teradata Database

Teradata Database SQL Functions, Operators, Expressions, and Predicates

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



Encodes a sequence of bits into a sequence of characters representing its encoding. The following encodings are supported:

  • BaseX
  • BaseY
  • Base64M (MIME)
  • where X is a power of 2 (for example, 2, 8, 16) and Y is not a power of 2 (for example, 10 and 36).




    Syntax element …

    Specifies …


    the name of the database where the function is located.


    the binary string value, that is, the sequence of characters to be encoded.


    the encoding FROM_BYTES uses to encode the sequence of characters specified by instring.

    ANSI Compliance

    This is ANSI SQL:2011 compliant.


    FROM_BYTES is an embedded services system function. For information on activating and invoking embedded services functions, see “Embedded Services System Functions” on page 24.

    Argument Types and Rules

    Expressions passed to this function must have the following data types:

  • instring = VARBYTE or BLOB
  • out_encoding = VARCHAR(64)
  • If out_encoding is not one of the supported encodings, an error is returned.

    If the resulting conversion overflows the result data type length, an error is generated.

    If either instring or out_encoding is NULL, the result is NULL.

    You can also pass arguments with data types that can be converted to the above types using the implicit data type conversion rules that apply to UDFs.

    Note: The UDF implicit type conversion rules are more restrictive than the implicit type conversion rules normally used by Teradata Database. If an argument cannot be converted to the required data type following the UDF implicit conversion rules, it must be explicitly cast.

    For details, see “Compatible Types” in SQL External Routine Programming.

    Result Type

    The result data type is VARCHAR or CLOB. Note that the return value may be NULL.


    The following query:

    SELECT from_bytes('5A1B'XB, 'base10');

    returns '23067'.


    The following query:

    SELECT from_bytes('5A3F'XB, 'ASCII');

    returns 'Z\ESC '.


    The following query:

    SELECT from_bytes('5A1B'XB, 'base16');

    returns '5A1B'.