HPlogo ALLBASE/SQL Reference Manual: HP 9000 Computer Systems > Chapter 7 Data Types

Type Conversion

» 

Technical documentation

Complete book in PDF
» Feedback

 » Table of Contents

 » Index

ALLBASE/SQL converts the type of a value in the following situations:

  • Including values of different types in the same expression.

  • Moving data from a host variable to a column or a column to a host variable of a different type.

The valid type combinations are shown in Table 7-1 “ALLBASE/SQL Data Types”

Table 7-3 Valid Type Combinations

Source Data TypeTarget Data Type
CHAR or VARCHAR CHAR or VARCHAR
 DATE, TIME DATETIME, or INTERVAL when CHAR value involved in date/time math or inserted into or compared to a date/time column
CHAR or VARCHAR BINARY or VARBINARY (from host variable/constant into a binary column only)
BINARY or VARBINARY BINARY or VARBINARY
BINARY or VARBINARY CHAR or VARCHAR (from column into host variable, or comparing a binary column with a char column or value)
DECIMAL, FLOAT, REAL, INTEGER, SMALLINT Any numeric type
DATE, TIME, DATETIME, INTERVAL CHAR or VARCHAR (except in LIKE predicate)

 

In some cases, such as the following, data conversion can lead to overflow or truncation:

  • Overflow can occur during these conversions:

    FLOAT

    to DECIMAL, INTEGER or SMALLINT

    FLOAT

    to REAL

    REAL

    to DECIMAL, INTEGER, or SMALLINT

    DECIMAL

    to DECIMAL, INTEGER, or SMALLINT

    INTEGER

    to DECIMAL or SMALLINT

    SMALLINT

    to DECIMAL

  • Overflow of the integer part and truncation of the fractional part of a number can occur during a FLOAT-to-DECIMAL conversion, because ALLBASE/SQL aligns the decimal points.

  • Truncation of the fractional part of a value occurs during these conversions:

    DECIMAL

    to SMALLINT or INTEGER

    DECIMAL

    to DECIMAL when the target scale is smaller than the source scale

    FLOAT

    to INTEGER, SMALLINT, DECIMAL, or REAL

    REAL

    to INTEGER, SMALLINT, or DECIMAL

  • Truncation can occur during these conversions if the target is too small:

    DATE, TIME, DATETIME or INTERVAL

    to VARCHAR or CHAR

    CHAR

    to VARCHAR, BINARY or VARBINARY

    VARCHAR

    to CHAR, BINARY or VARBINARY

    VARBINARY

    to BINARY, CHAR or VARCHAR

    BINARY

    to VARBINARY, CHAR, or VARCHAR

When you use numeric data of different types in an expression or comparison operation, the data type of the lesser type is converted to that of the greater type, and the result is expressed in the greater type. Numeric types have the following precedence:

  • FLOAT

  • REAL, DECIMAL

  • INTEGER

  • SMALLINT

Comparison operations or expressions involving different numeric data types result in conversion from one data type to another as explained in Table 7-4 “Conversions from Combining Different Numeric Data Types”

Table 7-4 Conversions from Combining Different Numeric Data Types

Operations containing:Result:
DECIMAL and INTEGER types onlyAll participating integers are converted to DECIMAL quantities having a precision of 10 and a scale of 0.
DECIMAL and SMALLINT types onlyAll participating SMALLINT values are converted to DECIMAL quantities having a precision of 5 and a scale of 0.
One item of type FLOATAll participating integer and decimal operands are converted to FLOAT quantities and precision can be lost.
One item of type REALAll arithmetic involving REAL operands results in a type of FLOAT. All participating integer and decimal operands are converted to FLOAT quantities and precision can be lost.

 

Feedback to webmaster