The basic operations of SQL are assignment and comparison. Assignment operations are performed during the execution of INSERT, UPDATE, FETCH, SELECT INTO, VALUES INTO and SET transition-variable statements. Arguments of functions are also assigned when invoking a function. Comparison operations are performed during the execution of statements that include predicates and other language elements such as MAX, MIN, DISTINCT, GROUP BY, and ORDER BY.
The basic rule for both operations is that the data type of the operands
involved must be compatible. The compatibility rule also applies to set
operations (see Rules for Result Data Types). The compatibility matrix is as follows.
Table 7. Data Type Compatibility for Assignments and Comparisons
Operands | Binary Integer | Decimal Number | Floating Point | Character String | Graphic String | Date | Time | Time- stamp | Binary String | UDT | ||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Binary Integer | Yes | Yes | Yes | No | No | No | No | No | No | 2 | ||
Decimal Number | Yes | Yes | Yes | No | No | No | No | No | No | 2 | ||
Floating Point | Yes | Yes | Yes | No | No | No | No | No | No | 2 | ||
Character String | No | No | No | Yes | No | 1 | 1 | 1 | No 3 | 2 | ||
Graphic String | No | No | No | No | Yes | No | No | No | No | 2 | ||
Date | No | No | No | 1 | No | Yes | No | No | No | 2 | ||
Time | No | No | No | 1 | No | No | Yes | No | No | 2 | ||
Timestamp | No | No | No | 1 | No | No | No | Yes | No | 2 | ||
Binary String | No | No | No | No 3 | No | No | No | No | Yes | 2 | ||
UDT | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | Yes | ||
|
A basic rule for assignment operations is that a null value cannot be assigned to a column that cannot contain null values, nor to a host variable that does not have an associated indicator variable. (See References to Host Variables for a discussion of indicator variables.)