The syntax rules listed here are part of the column description in the commands for importing and exporting application data.
If you want to use keywords as column names, you must place them in double quotation marks.
<load_column_spec> ::=
<column_descriptor> [<null_condition>]
| <column_assignment>
<column_descriptor> |
<valCOLUMN_NAME> <field_pos> <format_spec> |
<valCOLUMN_NAME> |
Name of Column |
<field_pos> |
|
<format_spec> |
<field_format> [HEX] [<numerical_functions>] |
<null_condition> |
NULL [IF] <condition> | DEFAULT NULL |
<condition> |
|
<column_assignment> |
<valCOLUMN_NAME>
'<valLITERAL>' |
<valCOLUMN_NAME> |
Name of Column |
<valLITERAL> |
Constant |
<generate_spec> |
<format_spec> ::= <field_format> [HEX] [<numerical_functions>]
<field_format> |
|
HEX |
You can define HEX values. |
<numerical_functions> |
<scale_spec> |
<scale_spec> |
SCALE <valSCALE_FACTOR> |
<valSCALE_FACTOR> |
The scaling factor valSCALE_FACTOR can be positive or negative. The value to which the syntax rule refers is multiplied by the corresponding power of ten. |
<round_or_trunc_spec> |
ROUND <valFRACTION> | TRUNC <valFRACTION> |
<valFRACTION> |
Number of decimal places The value must be between 0 and 18. This function does not have any effect if the number does not have any decimal places. |
In a command for importing application data, you use the syntax rule load_column_spec to specify the data records in the data stream which are to be loaded. You assign the data fields in the data stream to the columns in the target table and specify the external data types as well as the conditions for importing the data.
IMPORT TABLE hotel.customer
DATA INSTREAM FILE 'customer.data'
cno 1
title 2
firstname 3
name 4
zip 5
address 6
IMPORT TABLE hotel.reservation
DATA INSTREAM FILE 'reservation.data' FORMATTED BINARY
rno 01-04 INTEGER
cno 05-08 INTEGER
hno 09-12 INTEGER
type 13-18 CHAR
arrival 19-28 CHAR
departure 29-38 CHAR
Data must exist in the data stream for every column that you specify in the import command.
If you do not specify columns in the target table in the command, the entire column is populated with the default value defined for this column during the import operation. The NULL value is imported if no specific default value is defined for the column.
IMPORT TABLE hotel.customer
DATA INSTREAM FILE 'customer.data'
cno 1
name 4
address 6
title, firstname, and zip are filled with the default value when the data is loaded.
Key columns and mandatory columns (columns that are defined as NOT NULL without a default value) must be specified in the import command. Otherwise, processing terminates with an SQL error.
IMPORT TABLE hotel.customer
DATA INSTREAM FILE 'customer.data'
name 4
zip 5
address 6
The command is terminated with an SQL error, as the column cno is missing.
If you do not specify any columns for the target table in the import command, the table is imported as if all columns in the target table were specified in the command. If this is the case, data must exist in the data stream for all of the columns in the target table.
IMPORT TABLE hotel.customer
DATA INSTREAM FILE 'customer.data'
Data must exist in the source file for all of the columns in the data stream.
In a command for importing application data, you can use this syntax rule to assign a data field in the data stream to a column in the target table.
To do so, you specify the column name, the position, and the external data type of the data in the data stream.
IMPORT TABLE hotel.reservation
DATA INSTREAM FILE 'reservation.data' FORMATTED BINARY
rno 01-04
INTEGER
cno 05-08
INTEGER
hno 09-12
INTEGER
type 13-18
INTEGER
arrival 19-28 CHAR
departure 29-38 CHAR
In a command for importing or exporting application data, use the format_spec syntax rule to specify the data fields in the data stream (external data type, position, and so on).
You can use the syntax rule numerical_function to scale (scale_spec), round, or truncate (round_or_trunc_spec) numeric data values when you import data from the data stream to the target table or export data from the source table to the data stream.
Note that you must always specify scale_spec before round_or_trunc_spec.
EXPORT COLUMNS * FROM hotel.room
MAP COLUMNS
hno 1
type 2
free 3
price 4 SCALE -1 TRUNC 2
DATA OUTSTREAM FILE 'room.data'
You use the syntax rule round_or_trunc_spec to specify the number of decimal places for a number.
·
ROUND <valFRACTION>
The value is rounded off at the (<valFRACTION>+1) th decimal place. If
this number is >= 5, the value is rounded up. If it is < 5, the value is
rounded down. The result is a number in which the (<valFRACTION>+1)th and all subsequent
decimal places are equal to 0. However, the first digits in the number may
have been changed by rounding.
·
TRUNC <valFRACTION>
The (<valFRACTION>+1)th and all
subsequent decimal places of the value are set to 0. The first <valFRACTION> decimal places remain unchanged.
In a command for importing data, you use the syntax rule null_condition to specify the conditions under which the NULL value should be imported into a column of the target table.
When the condition is evaluated, the shorter of the comparison values (value in the data stream or the NULL value representation) is filled with blank characters.
A check is made before each line in the data stream is imported to see whether the condition formulated for the columns applies. If it does, the NULL value is inserted in this column. If not, the value from the assigned field in the data stream is inserted.
You can use the DEFAULT-NULL condition if the NULL value in the data stream is represented in the same way for all columns that you want to import from the target table. The character string that you need to specify after NULL IF POS is only entered once as a NULL specification in the DEFAULT-NULL condition.
You cannot import columns defined as key columns (KEY) or NOT NULL with the NULL value. If you do, the table import action terminates and the appropriate error message is displayed.
If you defined a default other than NULL for columns when you created the table in the database instance, you cannot import NULL values into the columns. In this case, the Loader uses the default value defined for the column instead of the NULL value.
You want to load the data from the data stream room.datainto the database instance, and you want to load the NULL value into certain columns of the target table. Define a separate condition for each of these columns. The NULL value is entered if this condition is met.
IMPORT TABLE hotel.room
DATA INSTREAM FILE 'room.data'
hno 1
type 2
free 3 NULL IF POS 3 = '0'
price 4 NULL IF POS 4 <> 'XXXX'
You want to load the data from the data stream room.datainto the database instance, and you want to load the NULL value into certain columns of the target table. The same '?' representation of the NULL value applies to all columns in the command where DEFAULT NULL is specified.
IMPORT TABLE hotel.room
DATA INSTREAM FILE 'room.data'
NULL '?'
hno 1
type 2
free 3 DEFAULT NULL
price 4 DEFAULT NULL
You can use the syntax rule column_assignment to specify that a constant value is loaded into the specified column for each loaded data record, and which value this constant is to have.
In the command, enter the constant or the special constant generate_spec instead of a position specification. Now, data will not be loaded from the data stream for the appropriate column.
If the data stream is empty, the constants specified in the command are not loaded.
See also:
Importing Constants and Special Constants