HP 3000 Manuals

Type Conversion [ ALLBASE/SQL Reference Manual ] MPE/iX 5.5 Documentation


ALLBASE/SQL Reference Manual

Type Conversion 

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

          Table 7-3.  Valid Type Combinations 

--------------------------------------------------------------------------------------------
|                                                     |                                    |
|                  Source Data Type                   |          Target 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,         to VARCHAR or CHAR
       DATETIME or
       INTERVAL

       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:

          Table 7-4.  Conversions from Combining Different Numeric Data Types 

--------------------------------------------------------------------------------------------
|                                    |                                                     |
|       Operations containing:       |                       Result:                       |
|                                    |                                                     |
--------------------------------------------------------------------------------------------
|                                    |                                                     |
| DECIMAL and INTEGER types only     | All participating integers are converted to DECIMAL |
|                                    | quantities having a precision of 10 and a scale of  |
|                                    | 0.                                                  |
|                                    |                                                     |
| DECIMAL and SMALLINT types only    | All participating SMALLINT values are converted to  |
|                                    | DECIMAL quantities having a precision of 5 and a    |
|                                    | scale of 0.                                         |
|                                    |                                                     |
| One item of type FLOAT             | All participating integer and decimal operands are  |
|                                    | converted to FLOAT quantities and precision can be  |
|                                    | lost.                                               |
|                                    |                                                     |
| One item of type REAL              | All 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.                          |
|                                    |                                                     |
--------------------------------------------------------------------------------------------



MPE/iX 5.5 Documentation