A literal is data whose value cannot be modified within the program. Literals can be numeric literals (which represent numbers) or character string literals, national character string literals, and mixed character string literals (which represent character strings).
The following figure shows the literals that can be specified in SQL.
Figure 1-4 Specifiable literals
The following table lists the notation used for literals.
Table 1-11 Notations for literals
Literal | Notation | Data type interpreted by HiRDB | |
---|---|---|---|
Integer#1 | [sign]unsigned-integer Examples: -123 45 6789 | Integer represented as a string of unsigned integers with the sign represented by + or -. | INTEGER |
Decimal | [sign]integer-part.fractional-part Examples: 12.3 -456. .789 | An integer part and a fractional part represented as an unsigned integer. Either the integer part or the fractional part may be omitted; the decimal point cannot be omitted. | DECIMAL(m[,n]), where m and n denote numbers of digits. |
Floating-point numeric | mantissaExponent Examples: 1.0E2 .5E+67 | Either an integer literal or a decimal literal as the mantissa, followed by a 1- to 3-digit integer literal as the exponent. The exponent represents a power of 10. The character E cannot be omitted. | FLOAT |
Character string#3 | 'character-string' Examples: 'HITACHI' '88' '''95.7.30' | A character string is expressed by a string of 1-byte characters. To use an single quotation mark in a character string, two consecutive single quotation marks must be specified. The maximum length is 32,000 bytes. | VARCHAR(n), where n indicates the length of the character string.#2 |
Hexadecimal character string literal#6 | X'hexadecimal-character-string-literal' Examples: X'82A0', X'82a0' | A hexadecimal character string literal is represented with characters 0-9 and A-F (or a-f). The maximum allowable length of a hexadecimal character string literal is 64,000 characters, in a multiple of 2. Two hexadecimal characters make up one byte. | VARCHAR(n) where n is the indicated character string length ![]() |
National character string#3, #4, #5 | N'national-character-string' Example: N'SQL-syntax' | A character string is expressed by a string of 2-byte characters. The maximum length is 16,000 characters. | NVARCHAR(n), where n indicates the length of the character string.#2 |
Mixed character string#3, #4 | M'character-string' Example: M'1996' | A character string is expressed by a string of 1- and 2-byte characters. The maximum length is 32,000 bytes. | MVARCHAR(n), where n indicates the length of the character string.#2 |
The following table lists restrictions on the use of numeric literals.
Table 1-12 Restrictions on use of numeric literals
Numeric literal type | Range | Maximum number of digits (including leading zeros) |
---|---|---|
Integer | -2147483648 to 2147483647 | 10 |
Decimal | -(1039 - 1) to -10-38, 0, 10-38 to 1039 - 1 | 38 |
Floating-point numeric# | About -1.7 x 10308 to -4.9 x 10-324, 0, About 4.9 x 10-324 to 1.7 x 10308 | Mantissa: 17 Exponent: 3 |