Hitachi

Hitachi Advanced Database SQL Reference


6.3.2 Description format of literals

The following table lists the description formats and assumed data types of literals.

Table 6‒10: Description formats and assumed data types of literals

No.

Type of literal

Description format

Assumed data type

1

Numeric literal

Integer literal

  • Description format

    [sign]unsigned-integer

  • Examples

    45, 6789, -123

  • Explanation

    The sign portion is expressed as + or -. + can be omitted.

INTEGER

2

Decimal literal

  • Description format

    [sign]integer-part.fractional-part

  • Examples

    12.3, -456., .789

  • Explanation

    The sign portion is expressed as + or -. + can be omitted.

    The integer part and fractional part are represented as unsigned integers. Either the integer part or fractional part must be specified. A decimal point must be specified.

DECIMAL(m[,n])

m,n: Number of specified digits

3

Floating-point numeric literal

  • Description format

    mantissaEexponent, or mantissaeexponent

  • Examples

    +1.0E+1, 1.0E2, -3.4e-01, .5E+67

  • Explanation

    The mantissa is expressed in the form of an integer or decimal literal.

    The exponent is written in the form of an integer literal of 1 to 3 digits. The exponent represents powers of 10.

    The letter E or e is required.

DOUBLE PRECISION

4

General literal

Character string literal

  • Description format

    'character-string'

  • Examples

    'HITACHI', '88', '''95.7.30'

  • Explanation

    A character string is enclosed in single quotation marks (' ). Half-width and/or full-width characters can be used.

    To use a single quotation mark within a character string, as in the example '95.7.30, specify two consecutive single quotation marks, as in the example above.

  • When n>0

    CHAR(n)

  • When n=0

    VARCHAR(1)

    with an actual length of 0

(where n indicates the length of the character string)

5

Date literal

  • Description format

    DATE'YYYY-MM-DD' or DATE'YYYY/MM/DD'

  • Examples

    DATE'2012-03-30'

    DATE'2012/03/30'

  • Explanation

    The year is expressed in four digits (YYYY), and the month (MM) and day (DD) in two digits. Pad the fields with zeros on the left as necessary.

    Specify values for YYYY, MM, and DD that are valid for the DATE type (for example, MM must be 01 to 12).

    No separators are permitted inside 'YYYY-MM-DD' and 'YYYY/MM/DD'.

DATE

6

Time literal

  • Description format

    TIME'hh:mm:ss.nn...n'

  • Examples

    TIME'11:03:58'

    TIME'11:03:58.123'

    TIME'11:03:58.123456'

    TIME'11:03:58.123456789'

    TIME'11:03:58.123456789012'

    TIME'11:03:58.'

  • Explanation

    The hour (hh), minutes (mm), and seconds (ss) are expressed in two digits. Pad the fields with zeros on the left as necessary.

    nn...n expresses the fractional seconds. nn...n represents 3, 6, 9, or 12 digits.

    To use fractional seconds, put a period between the seconds and the fractional seconds precision specification.

    If you omit the fractional seconds and specify only a period, the data is treated as having a fractional seconds precision of 0.

    An error results if the fractional seconds precision is more than 12.

    Specify values for hh, mm, ss, and nn...n that are valid for the TIME type (for example, hh must be 00 to 23).

    No separators are permitted inside 'hh:mm:ss.nn...n'.

TIME[(p)]

p: fractional seconds precision

7

Time stamp literal

  • Description format

    TIMESTAMP'YYYY-MM-DD hh:mm:ss.nn...n' or TIMESTAMP'YYYY/MM/DD hh:mm:ss.nn...n'

  • Examples

    TIMESTAMP'2012-03-30 11:03:58'

    TIMESTAMP'2012/03/30 11:03:58'

    TIMESTAMP'2014-07-30 11:03:58.123'

    TIMESTAMP'2014/07/30 11:03:58.123456789012'

    TIMESTAMP'2014-07-30 11:03:58.'

  • Explanation

    The format is YYYY-MM-DD (or YYYY/MM/DD) and hh:mm:ss, with a space between them.

    The year is expressed in four digits (YYYY), and the month (MM) and day (DD) in two digits. Pad the fields with zeros on the left as necessary.

    Similarly, pad the two-digit fields for hours (hh), minutes (mm), and seconds (ss) with zeros on the left as necessary.

    nn...n expresses the fractional seconds precision. nn...n represents 3, 6, 9, or 12 digits.

    To use fractional seconds, put a period between the seconds and the fractional seconds precision specification.

    If you omit the fractional seconds and specify only a period, the data is treated as having a fractional seconds precision of 0.

    An error results if the fractional seconds precision is more than 12.

    Specify values for YYYY, MM, DD, hh, mm, and ss that are valid for the TIMESTAMP type (for example, hh must be 00 to 23).

    No separators are permitted inside 'YYYY-MM-DD hh:mm:ss.nn...n' and 'YYYY/MM/DD hh:mm:ss.nn...n'.

TIMESTAMP[(p)]

p: fractional seconds precision

8

Hexadecimal-format binary literal

  • Description format

    X'hexadecimal-character-string' or x'hexadecimal-character-string'

  • Examples

    X'82A0'

    X'82a0'

    x'82A0'

  • Explanation

    hexadecimal-character-string is expressed using the hexadecimal digits 0 to 9 and A to F (or a to f).

    The number of characters in hexadecimal-character-string must be a multiple of 2. Two hexadecimal characters make one byte.

    The number of characters in hexadecimal-character-string cannot exceed 64,000.

    No separators are permitted inside hexadecimal-character-string.

  • When n > 0

    BINARY(n ÷ 2)

  • When n = 0

    VARBINARY(1)

    with an actual length of 0

(where n indicates the length of the hexadecimal character string)

9

Binary-format binary literal

  • Description format

    B'binary-character-string' or b'binary-character-string'

  • Examples

    B'01010101'

    b'01010101'

  • Explanation

    binary-character-string is expressed using the binary digits 0 and 1.

    The number of characters in binary-character-string must be a multiple of 8. Eight binary characters make one byte.

    The number of characters in binary-character-string cannot exceed 256,000.

    No separators are permitted inside binary-character-string.

  • When n > 0

    BINARY(n ÷ 8)

  • When n = 0

    VARBINARY(1)

    with an actual length of 0

(where n indicates the length of the binary character string)

The following table shows restrictions on the use of numeric literals.

Table 6‒11: Restrictions on the use of numeric literals

No.

Numeric literal

Range

Maximum number of digits (including leading zeros)

1

Integer literal#1

-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807

19 digits

2

Decimal literal

-(1038 - 1) to -10-38, 0,

and 10-38 to (1038 - 1)

38 digits

3

Floating-point numeric literal#2

Approximately -1.7 × 10308 to -2.3 × 10-308, 0, and approximately 2.3 × 10-308 to 1.7 × 10308

Mantissa part: 17 digits

Exponent part: 3 digits

#1

If a literal that exceeds the range of values for an integer literal is written in the notation used to represent integer literals, it will be interpreted as a decimal literal, with an assumed decimal point to the right of the literal.

#2

The exact range of values depends on the hardware representation.