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.
Types of Numeric Literals
There are three kinds of numeric literals:
Examples: Valid Numeric Literals
The following are examples of valid numeric literals.
Examples: Nonvalid Numeric Literals
The following are examples of 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.
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 SQL Functions, Operators, Expressions, and Predicates.
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, Teradata Database 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 SQL Functions, Operators, Expressions, and Predicates.