15.00 - FROM_BYTES - Teradata Database

Teradata Database SQL Functions, Operators, Expressions, and Predicates

Product
Teradata Database
Release Number
15.00
Content Type
Programming Reference
Publication ID
B035-1145-015K
Language
English (United States)
Last Update
2018-09-24

FROM_BYTES

Purpose  

Encodes a sequence of bits into a sequence of characters representing its encoding. 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 binary string value, that is, the sequence of characters to be encoded.

    out_encoding

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

    ANSI Compliance

    This is ANSI SQL:2011 compliant.

    Invocation

    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.

    Example  

    The following query:

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

    returns '23067'.

    Example  

    The following query:

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

    returns 'Z\ESC '.

    Example  

    The following query:

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

    returns '5A1B'.