Therefore, if the data to be added contains a null value or some other value dependent on the processing of the
application program, use an indicator variable. If an indicator variable is used, only one INSERT statement needs to
be coded. However, for processing in which the data must be specified as a null value, specify the keyword "NULL" to
simplify coding of the INSERT statement.
Figure: Example of adding a null value shows the execution results for the INSERT statement in Examples 1 and 2.
[Figure: Example of adding a null value]
Another method of specifying that data to be added is a null value is to omit the relevant column from the insert
column list and the insert value list. The following is an example of omitting the relevant column:
Example 3:
In this example, the column to which a null value is to be added is omitted. The data to be added is the
same as in Example 1 and Example 2.
INSERT INTO STOCKS. ORDER (CUSTOMER, PRODNO, ORDERQTY)
VALUES (78, 400, 50)
In Example 3, PRICE is not specified as a column name in the insert column list, nor is a value corresponding to
PRICE specified in the insert value list. In this case, a null value is defined as the default value for PRICE or the
added data is a null value because a default value was not defined. For more information on adding data for which a
default value is used, see "3.1.2 Using default values in data to be added."
Care must be taken to distinguish between whether the purpose of the processing for the application program is to
add a null value or to add a default value. The default value for a column may have been changed due to changes in
the design of the table. As a result, if the purpose of the processing is to add a null value, the methods shown in
Examples 1 or 2 should be used.
22