Using HASHBUCKET to Convert a BYTE Type to an INTEGER Type

Teradata Vantageā„¢ SQL Functions, Expressions, and Predicates

brand
Software
Teradata Vantage
prodname
Teradata Database
Teradata Vantage NewSQL Engine
vrm_release
16.20
category
Programming Reference
featnum
B035-1145-162K

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;