TO_BYTES - Teradata Database

SQL Functions, Operators, Expressions, and Predicates

Product
Teradata Database
Release Number
15.00
Language
English (United States)
Last Update
2018-09-24
dita:id
B035-1145
lifecycle
previous
Product Category
Teradata® Database

TO_BYTES

Purpose  

Decodes a sequence of characters in a given encoding into a sequence of bits. The following encodings are supported:

  • BaseX
  • BaseY
  • Base64M (MIME)
  • ASCII
  • 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  

    where:

     

    Syntax element …

    Specifies …

    TD_SYSFNLIB

    the name of the database where the function is located.

    instring

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

    in_encoding

    the encoding TO_BYTES uses to return the sequence of characters specified by instring.

    ANSI Compliance

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

    Invocation

    TO_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 = VARCHAR or CLOB
  • in_encoding = VARCHAR(64)
  • If in_encoding is not one of the supported encodings, an error is returned.

    If either instring or in_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 VARBYTE or BLOB.

    Example  

    The following query:

    SELECT CAST (TO_BYTES ('5A', 'base16') as BTYE (16));
    TO_BYTES('5A','base16')

    returns '5A-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 '

    Example  

    The following query:

    SELECT CAST (TO_BYTES ('-22EEVX', 'base36') as BYTE (16));
    TO_BYTES('-22EEVX','base36')

    returns 'F8-8D-33-23-00-00-00-00-00-00-00-00-00-00-00-00'