DEFAULTIF (fieldSelection)
Use DEFAULTIF(fieldSelection) to conditionally specifies whether a table column should receive a input data value (if provided) or a Db2 default value. You can define DEFAULTIF clauses for any column, regardless of whether the column has the WITH DEFAULT attribute.
You cannot specify DEFAULTIF for the following columns:
- ROWID
- LOB, CLOB, DBCLOB, XML
- ROW BEGIN, ROW END, and ROW CHANGE
You can specify DEFAUILTIF for IDENTITY columns if you use OVERRIDE(IDENTITY). The DEFAULTIF(fieldSelection) variable that you specify uses the same syntax as the field selection specified on a WHEN clause. For more information, see the field selection syntax diagram.
You can use multiple DEFAULTIF clauses for a variety of different conditions and different default values. The product checks the conditions in the specified order and selects the result based on the first matching condition.
(PTF BQU2361 applied) Defaultifvalue selection
In a DEFAULTIF statement, you can specify a default VALUE value that overrides any Db2 default values specified for the column when the table was created.
Value specification syntax
VALUE values
Value | Description |
---|---|
constant | A constant |
special register | A special register |
SQL-constant expression | An SQL expression involving constants, or special registers, or both |
NULL | Equivalent to a NULLIF clause |
For more information about SQL constant and special register, see BMC-AMI-Utilities-SQL-language.
Examples
The following table describes default values that BMC AMI Load generates when a DEFAULTIF condition is true and the column has no default value specified in the Db2 catalog:
Column type | Default value |
---|---|
Character or graphic | Blank |
Numeric | 0 |
Date | Current date |
Time | Current time |
Timestamp | Current time stamp |
The current date, time, and timestamp values are recomputed for each inserted row and therefore results might not be the same across the entire table.
Related topics