15.10 - Hexadecimal Integer Literals - Teradata Database

Teradata Database SQL Data Types and Literals

prodname
Teradata Database
vrm_release
15.10
category
Programming Reference
featnum
B035-1143-151K

Declares a hexadecimal integer literal value.

where:

 

This syntax element …

Specifies …

hexadecimal digits

a string of hexadecimal digits, where a hexadecimal digit is a character from 0 to 9, a to f, or A to F.

1

integers with a BYTEINT data type.

2

integers with a SMALLINT data type.

4

integers with an INTEGER data type. This is the default if 1, 2, 4, or 8 is not specified.

8

integers with a BIGINT data type.

Hexadecimal literals are Teradata extensions to the ANSI SQL:2011 standard.

Hexadecimal literals consist of 0 to 16 hexadecimal digits delimited by a matching pair of apostrophes. Spaces and new line characters are not allowed in a literal.

The modifiers following the X determine the hexadecimal literal data type.

 

IF a hexadecimal literal uses this form …

THEN the data type is …

AND the maximum hexadecimal digits is...

'hexadecimal digits'X

'hexadecimal digits'XI

'hexadecimal digits'XI4

INTEGER

8

'hexadecimal digits'XI2

SMALLINT

4

'hexadecimal digits'XI1

BYTEINT

2

'hexadecimal digits'XI8

BIGINT

16

Hexadecimal integer literals are represented by an odd or even number of hexadecimal digits. The hexadecimal literal is right‑justified. For example, the value 1000 can be expressed as any of the following:

   '3e8'X
   '0003e8'X
   '000003e8'X

1000 hex would be '1000'x, which is 16*16*16=4096.

'3e8'x = 3*16*16 + e*16 + 8 and e is 14 so we get 1000.

Note that the literal 1000 would be a SMALLINT whereas all the hex constants shown here are INTEGERs.

Consider the following table:

   CREATE TABLE id_pairs (region_id INTEGER, region CHAR(20));

Submit the following statement to find the value of the region column where the region_id is a hexadecimal value of 3e8:

   SELECT region FROM id_pairs WHERE region_id = '3e8'X;