1.3 Literals

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).

Figure 1-4 shows the literals that can be specified in SQL. Table 1-9 shows the notations for literals and the data types that can be interpreted by HiRDB. Table 1-10 lists restrictions on using numeric literals.

Figure 1-4 Specifiable literals

[Figure]

Table 1-9 Notations for literals

LiteralNotationData type interpreted by HiRDB
Integer1[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 numericmantissaEexponent
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 string3'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 single quotation marks in succession 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 literal6X'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 [Figure] 2.2
National character string3, 4, 5N'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 string3, 4M'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
Note
Date and time values can be specified as a literal using a predefined character string representation. Similarly, date intervals and time intervals can be specified in SQL statements as decimal expression literals (decimal literals).
1 If a literal that exceeds the allowable range of an integer literal is specified in the integer literal notation, HiRDB assumes the decimal point to be at the right side of the literal and interprets the literal to be a decimal literal.
2 In the case of a character string literal (' ', X' ', N' ', or M' ') whose length is 0, n is 1.
3 For character strings that can be specified in COMMENT, EXECUTE IMMEDIATE, and PREPARE statements, see the syntax section for each SQL statement.
4 When lang-c is specified in the pdsetup command as the character codes type, national character data and mixed character data cannot be defined (UNIX version only).
5 National character string literals cannot be used when the utf-8 character code type is specified in the pdntenv command (pdsetup command in the UNIX version).
6 Hexadecimal character string literals differ from character string literals only in the coding format. In this manual, any description on character string literals is also applicable to hexadecimal character string literals.

Table 1-10 Restrictions on use of numeric literals

Numeric literal typeRangeMaximum number of digits (including leading zeros)
Integer-2147483648​ to 2147483647​10
Decimal[Figure]10-29 to [Figure](1030 - 1)29
Floating-point numeric*Approx. [Figure]4.9[Figure]10-324 to [Figure]1.7[Figure]10308Mantissa: 17
Exponent: 3
* The allowable range of values is limited by the data representation available on the hardware used to execute the SQL.
Organization of this section
1.3.1 Predefined character string representation of date data
1.3.2 Predefined character string representation of time data
1.3.3 Predefined character string representation of time stamp data
1.3.4 Decimal representation of date interval data
1.3.5 Decimal representation of time interval data
1.3.6 Decimal representation of datetime interval data