TO_BYTE
Purpose
Converts a numeric data type to the Teradata Database server byte representation (byte value) of the input value.
Syntax
where:
Syntax element… |
Specifies… |
TD_SYSFNLIB |
the name of the database where the function is located. |
target_arg |
a numeric expression. |
ANSI Compliance
This is a Teradata extension to the ANSI SQL:2011 standard.
Description
The number of bytes returned by the function varies according to the data type of the target_arg value.
For information on the server representation of integral values, see SQL Data Types and Literals.
If target_arg is NULL, the function returns NULL.
Argument Types and Rules
TO_BYTE is an overloaded scalar function. It is defined with the following parameter data types:
All expressions passed to this function must either match these declared data types or can be converted to these 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 one of the declared data types by following UDF implicit conversion rules, it must be explicitly cast. For details, see “Compatible Types” and “Parameter Types in Overloaded Functions” in SQL External Routine Programming.
If the argument cannot be converted to one of the declared data types, an error is returned indicating that no function exists that matches the DML UDF expression submitted.
For more information on overloaded functions, see “Function Name Overloading” in SQL External Routine Programming.
Result Type and Attributes
The result data type is a BYTE value (a fixed byte data type). The size of the byte string returned varies according to the data type of the target_arg input argument as shown in the following table:
IF the data type of target_arg is... |
THEN the result type is... |
AND the result format is the default format for... |
BYTEINT |
BYTE(1) |
BYTE(1) |
SMALLINT |
BYTE(2) |
BYTE(2) |
INTEGER |
BYTE(4) |
BYTE(4) |
BIGINT |
BYTE(8) |
BYTE(8) |
The default title for TO_BYTE is: TO_BYTE(target_arg).
For information on default data type formats, see SQL Data Types and Literals.
Example
In the following query, the input argument 23 has a data type of BYTEINT and a binary representation of 00010111. Performing a TO_BYTE operation on this value results in the value 00010111 being returned with the data type of BYTE(17).
SELECT TO_BYTE(23);