Numeric Literals | Data Types and Literals | Teradata Vantage - 17.10 - Numeric Literals - Advanced SQL Engine - Teradata Database

Teradata Vantage™ - Data Types and Literals

Product
Advanced SQL Engine
Teradata Database
Release Number
17.10
Release Date
July 2021
Content Type
Programming Reference
Publication ID
B035-1143-171K
Language
English (United States)

Definition

A numeric literal is a string of 1 to 40 characters selected from the following:
  • plus sign
  • minus sign
  • digits 0 through 9
  • decimal point

Numeric literals are also referred to as numeric constants.

Vantage also supports a hexadecimal form of numeric literals to represent integer values. For more information, see Hexadecimal Integer Literals.

Types of Numeric Literals

There are three kinds of numeric literals:

Examples: Valid Numeric Literals

Type Examples
BYTEINT 127 -36 -128
SMALLINT 32767 -12000 -32768
INTEGER 32768 -60400 2147483647
DECIMAL 0.0 -23554367273149967931. 2147483650
FLOATING POINT 1E1 1.4E6 18E-3

Examples: Nonvalid Numeric Literals

This literal is not valid … Because it contains …
123456789012345678901234567890123456789 more than 38 digits.
$20,000.00 a dollar sign and a comma.
-38.7E2945 four digits following the E.
For the rules on what constitutes valid numeric literals, see the following sections:

Determining the Data Type of a Numeric Literal

The data type of a numeric literal is determined by the range of the literal value. The type used is the smallest that can contain the value.

For example, the data type of the numeric literal 127 is BYTEINT because it is the smallest type that can fit the value 127.

For decimal literals, the total number of digits determine the precision and the number of digits to the right of the decimal point determine the scale.

FOR details on … SEE …
the range of values of integer literals Integer Literals.
determining the scale and precision of a decimal literal Decimal Literals.

Implicit Conversion of Numeric Literals

Depending on the kind of operation performed or the type of column in which a value is to be stored, SQL may convert numeric literal constants from one numeric data type to another.

If a literal is outside the range for its required type, an error is reported during conversion.

For more information on numeric to numeric data type conversions, see Teradata Vantage™ - SQL Functions, Expressions, and Predicates, B035-1145.

Converting Character Strings to Numeric Literals

Character data can contain a string that is intended to be interpreted as a numeric value (for example, '15'). In such cases, Vantage attempts to convert the string to a numeric value whenever the context makes such a conversion necessary. If the character string does not represent a valid numeric value, an error is reported.

When data in a character column must be compared with data in a numeric column, the character data and the numeric data are converted to FLOAT before the comparison is made. Note that this can result in repeated conversions during data access.

If numeric data is defined and stored as a character string in a character column, and a SELECT operation uses a full table scan to compare the character column with a numeric literal, then the character column is converted to numeric in every row of the table.

For more information on character to numeric data type conversions, see Teradata Vantage™ - SQL Functions, Expressions, and Predicates, B035-1145.