16.20 - Using HASHBUCKET to Convert a BYTE Type to an INTEGER Type - Advanced SQL Engine - Teradata Database

Teradata Vantage™ - SQL Functions, Expressions, and Predicates

Product
Advanced SQL Engine
Teradata Database
Release Number
16.20
Release Date
March 2019
Content Type
Programming Reference
Publication ID
B035-1145-162K
Language
English (United States)

When a byte data type is the source type of a conversion using CAST syntax or Teradata Conversion syntax, the target data type must also be a byte type.

To convert a BYTE(1) or BYTE(2) data type to INTEGER, you can use the HASHBUCKET function.

Consider the following table definition:

   CREATE TABLE ByteData(b1 BYTE(1), b2 BYTE(2));

To convert column b1 to INTEGER regardless of the system setting of the hash bucket size, use the following:

   SELECT HASHBUCKET('00'XB || b1 (BYTE(4))) / ((HASHBUCKET()+1)/65536)
   FROM ByteData;

To convert column b2 to INTEGER regardless of the system setting of the hash bucket size, use the following:

   SELECT HASHBUCKET(b2 (BYTE(4))) / ((HASHBUCKET()+1)/65536)
   FROM ByteData;