DB2 数据移动实用工具 -- 导出、导入和载入 -- 支持各种各样基于用以将数据移入或移出数据库表的文件类型的选项。这些文件类型修饰符极大地扩展了数据移动实用工具的功能,并且可用于提高它们的性能。本文描述了所支持的所有修饰符,并通过工作示例展示了应如何正确使用它们。



IBM ®DB2 ®Universal Database TM(DB2 UDB)数据移动实用工具(导出、导入和载入)支持大量各种各样的选项,几乎支持您可能碰到的任何一种场景,因此相应 DB2 UDB 命令的语法相当复杂。为了最大限度地降低复杂性,但却最大化这些实用工具的通用性,这些命令的语法中包括功能强大的 MODIFIED BY 子句,这是一种根据所使用的输入或输出文件类型来指定处理选项的好方式(见图 1)。这些基于文件类型的处理选项被称作 文件类型修饰符



图 1. MODIFIED BY 子句包含在 DB2 EXPORT、IMPORT 和 LOAD 命令的语法中。同一命令中可以指定不止一个修饰符。



文件类型修饰符详述



目前存在近 50 个文件类型修饰符(见表 1;单击修饰符名称以跳到后面的表中查看其描述)。某些修饰符是为了让实用工具运行得更快而设计的,但大多数是用于提高数据移动实用工具的通用性和灵活性。



本文描述了所支持的所有文件类型修饰符,并提供了展示如何正确使用它们的工作示例。这些示例来自于命令脚本;您可以自己复制、粘贴以及运行它们。大多数示例是基于 DB2 UDB 中所附带的 SAMPLE 数据库的。少数示例需要 SAMPLE 数据库之外的场景,但是,您可以将到 SAMPLE 数据库的连接作为一个起始点。



表 2 - 6 中描述了这些修饰符。每张独立的表对应着特定的文件类型所支持的修饰符,包括所有文件类型都支持的修饰符、ASC 或 DEL 都支持的修饰符、只被 ASC 支持的修饰符、只被 DEL 支持的修饰符、只被 PC/IXF 支持的修饰符。



打开db2数据库是在哪个文件 db2加载数据文件_文件类型

文件类型入门



非定界 ASCII(ASC)文件是一个 ASCII 字符流。数据流中的行由行定界符分隔,而行中的每一列则通过起始和结束位置来定义。可以使用 IMPORT 或 LOAD 命令中的 METHOD L 参数来指定这些“成对位置”。每一对都表示一行里的字节位置。不支持到 ASC 文件类型的数据导出。


定界 ASCII(DEL)文件也是一个 ASCII 字符流。数据流中的行由行定界符分隔,行中的列值由列定界符分隔。文件类型修饰符可用于修改这些定界符的默认值。可以使用 IMPORT 或 LOAD 命令中的 METHOD P 参数来指定列位置。您必须小心确保您所选择的定界符字符不包含在需要移动的数据中;否则,可能会出现意想不到的错误!还请记住,不可以将换行符、回车或空格作为定界符,也不可以将默认的小数点(句号)作为字符串定界符。哦,还有另一件事:DATALINK 值的字段分隔符一定不能与用作行、列或字符串定界符的字符相同。关于 DB2 数据移动实用工具的定界符限制,请参阅 DB2 信息中心


PC/IXF

表 1. 版本 8.1.4 为止 DB2 UDB 所支持的导入、导出和载入实用工具的文件类型修饰符。



修饰符

适用的文件类型

修饰符

适用的文件类型

anyorder

所有类型

indexschema= schema

PC/IXF

binarynumerics

ASC

keepblanks

DEL

chardel x

DEL

lobsinfile

所有类型

codepage= x

ASC 或 DEL

no_type_id

所有类型

coldel x

DEL

nochardel

DEL

compound= x

所有类型

nochecklengths

ASC 或 PC/IXF

dateformat=" x"

ASC 或 DEL

nodefaults

所有类型

datesiso

DEL

nodoubledel

DEL

decplusblank

DEL

noheader

所有类型

decpt x

DEL

norowwarnings

所有类型

delprioritychar

DEL

nullindchar= x

ASC

dldel x

DEL

packeddecimal

ASC

dumpfile= x

ASC 或 DEL

pagefreespace= x

所有类型

fastparse

ASC 或 DEL

reclen= x

ASC

forcein

PC/IXF

striplzeros

DEL

generatedignore

所有类型

striptblanks

ASC

generatedmissing

所有类型

striptnulls

ASC

generatedoverride

所有类型

timeformat=" x"

ASC 或 DEL

identityignore

所有类型

timestampformat=" x"

ASC 或 DEL

identitymissing

所有类型

totalfreespace= x

所有类型

identityoverride

所有类型

usedefaults

所有类型

implieddecimal

ASC 或 DEL

usegraphiccodepage

ASC 或 DEL

indexfreespace= x

所有类型

zoneddecimal

ASC

indexixf

PC/IXF


表 2. 可用于所有支持文件类型的文件类型修饰符



修饰符

Export

Import

Load

描述

示例

anyorder

no

no

yes

指定载入实用工具可以以任何次序处理输入数据,该选项可在对称多处理(SMP)系统上带来更好的性能。如果 LOAD 命令中的 CPU_PARALLELISM 参数值为 1,则忽略该修饰符。

create table newemp like employee;

export to empdata.del of del messages export.msg select * from employee;

load from empdata.del of del modified by anyorder messages load.msg insert into newemp cpu_parallelism 2;

compound x

no

yes

no

指定 DB2 导入实用工具每次插入一块( x行)数据,而非每次插入一行。这可以导致性能的提高。 x的值可以是 1 至 100 之间的任意整数(包含 1 和 100 在内)。导入实用工具使用非原子复合 SQL 来插入数据:不管是否有错,都会尝试所有的插入。

create table emptemp like employee;

export to empdata.ixf of ixf messages export.msg select * from employee;

import from empdata.ixf of ixf modified by compound=100 messages import.msg insert into emptemp;

generatedignore

no

yes

yes

指定导入或载入输入文件中的任何生成列的值都会被忽略,并且会为每一行生成一个新的值。

考虑载入输入文件 staffdata.del 的内容为:"Dirk",90000.00,1000.00:

create table newstaff (name varchar(16) not null, salary decimal(9,2), bonus decimal(9,2) generated always as (salary/10));

load from staffdata.del of del modified by generatedignore messages load.msg insert into newstaff;

select * from newstaff;

generatedmissing

no

yes

yes

指定导入或载入输入文件不包含任何目标表中生成列的值。

考虑载入输入文件 staffdata.del 的内容为:"Crystal",102000.00:

create table newstaff (name varchar(16) not null, salary decimal(9,2), bonus decimal(9,2) generated always as (salary/10));

load from staffdata.del of del modified by generatedmissing messages load.msg insert into newstaff;

select * from newstaff;

generatedoverride

no

no

yes

指定在将数据载入一个带有 GENERATED ALWAYS 列的表中时,要使用载入输入文件中生成列的值。如果您使用了该修饰符,您的表在执行载入操作之后,将处于 检查暂挂状态,以便给您机会验证新数据的完整性。本例中的完整性是指与生成列规范的一致性。若要使表脱离该状态,且 验证输入值,就在执行载入操作之后发出下列命令: set integrity for < table-name> generated column immediate unchecked 。若要解除该表的检查暂挂状态,且验证输入值,就发出下列命令: set integrity for < table-name> immediate checked

考虑载入输入文件 staffdata.del 的内容为:"Jack",500000.00,50000:

create table newstaff (name varchar(16) not null, salary decimal(9,2), bonus decimal(9,2) generated always as (salary/10));

load from staffdata.del of del modified by generatedoverride messages load.msg insert into newstaff;

set integrity for newstaff immediate checked;

select * from newstaff;

identityignore

no

yes

yes

指定忽略导入或载入输入文件中任何标识列的值,并为每一行生成一个新的标识值。

考虑载入输入文件 custdata.del 的内容为:1,"Jacek":

create table customers (custno smallint not null generated always as identity (start with 500, increment by 1), custname varchar(16));

load from custdata.del of del modified by identityignore messages load.msg insert into customers;

select * from customers;

identitymissing

no

yes

yes

指定导入或载入输入文件不包含任何目标表中标识列的值。

考虑载入输入文件 custdata.del 的内容为:"Helmut":

create table customers (custno smallint not null generated always as identity (start with 500, increment by 1), custname varchar(16));

load from custdata.del of del modified by identitymissing messages load.msg insert into customers;

select * from customers;

identityoverride

no

no

yes

指定在将数据载入一个带有 GENERATED ALWAYS 标识列的表中时,要使用的载入输入文件中标识列的值;任何标识列上值为空(或为 null 值)的行都会被拒绝。

考虑载入输入文件 custdata.del 的内容为:3,"Shrek":

create table customers (custno smallint not null generated always as identity (start with 500, increment by 1), custname varchar(16));

load from custdata.del of del modified by identityoverride messages load.msg insert into customers;

select * from customers;

indexfreespace= x

no

no

yes

指定一个 0 到 99 之间的整数值(包含 0 和 99 在内),用于表示重新构建目标表上所定义的索引时,每个索引页中剩余空闲空间的百分比。较多的空闲空间意味着,将来执行数据插入和更新时可能会不那么需要进行表重组。 indexfreespace 的值比创建索引期间所指定的 PCTFREE 参数值具有更高的优先权。

create table newemp like employee;

export to empdata.del of del messages export.msg select * from employee;

load from empdata.del of del modified by indexfreespace=30 messages load.msg insert into newemp;

lobsinfile

yes

yes

yes 1

指定要将大对象(LOB)数据导出到 LOBS TO 子句中所指定的位置,或者从 LOBS FROM 子句中所指定的位置导入或载入。

export to empphoto.ixf of ixf lobs to /home/melnyk/ lobfile photo modified by lobsinfile messages export.msg select * from emp_photo;

no_type_id

no

yes

no

指定导入数据文件不包含 type_id列数据。该修饰符在将数据(起初是从一个常规或非类型化表导入的)导入到层次结构中的单个子表时十分有用。

如何从常规表中导出数据,然后将之导入层次结构中的单个子表的工作示例不属于本文的讨论范围。关于在类型化表之间移动数据的信息,请参阅 IBM DB2 Universal Database Data Movement Utilities Guide and Reference

nodefaults

no

yes

no

指定如果输入数据文件中缺少一列,则不导入该列上所定义的默认值。

考虑导入数据文件 tabdata.del 的内容为:9999:

create table tab1 (col1 integer, col2 integer with default 25);

import from tabdata.del of del modified by nodefaults method p (1) messages import.msg insert into tab1;

select * from tab1;

noheader

no

no

yes

指定输入数据文件的开头不存在分区头。在分区数据库环境中,执行 LOAD_ONLY 操作期间,分区头用于验证该文件是否只包含属于特定数据库分区的数据。可以在将数据载入单个数据库分区上所定义的表中时指定该修饰符,因为如果是那样的话,就不可能将数据载入错误的数据库分区。

如何在分区数据库环境中载入数据的工作示例超出了本文的讨论范围。关于在分区数据库环境中移动数据的信息,请参阅 IBM DB2 Universal Database Data Movement Utilities Guide and Reference

norowwarnings

no

yes

yes

指定在执行导入或载入操作时,取消关于拒绝某行的警告消息。

考虑载入输入文件 tabdata.del 的内容为:12f,"Sally":

create table tab1 (col1 integer not null, col2 varchar(10), primary key (col1));

load from tabdata.del of del modified by norowwarnings messages load.msg insert into tab1;

pagefreespace= x

no

no

yes

指定一个 0 到 100 之间的整数值(包含 0 和 100 在内),用于表示每个数据页所剩空闲空间的百分比。较多空闲空间意味着,将来执行数据插入和更新时可能会不那么需要进行表重组。 pagefreespace 的值比该表中可由 ALTER TABLE 语句来修改的 PCTFREE 参数值具有更高的优先权。

create table newemp like employee;

export to empdata.del of del messages export.msg select * from employee;

load from empdata.del of del modified by pagefreespace=50 messages load.msg insert into newemp;

totalfreespace= x

no

no

yes

指定一个大于等于 0 的整数,用于表示作为空闲空间附加至表尾的数据页占表中总页数的百分比。

create table newemp like employee;

export to empdata.del of del messages export.msg select * from employee;

load from empdata.del of del modified by totalfreespace=110 messages load.msg insert into newemp;

usedefaults

no

yes

yes

指定如果输入数据文件没有包含某列的值,就导入或载入该列上所定义的默认值。

考虑导入数据文件 tabdata.del 的内容为:9999,:

create table tab1 (col1 integer, col2 integer with default 25);

import from tabdata.del of del modified by usedefaults messages import.msg insert into tab1;

select * from tab1;

1该修饰符不能用于 CURSOR 文件类型。

表 3. 可用于 ASCII(ASC 或 DEL)文件类型的文件类型修饰符



修饰符

Export

Import

Load

描述

示例

codepage= x

见表 5

yes

yes 1

指定一个 ASCII 字符串,用于表示要导入或载入数据的源代码页。如果您需要当在运行于不同代码页的系统之间移动数据时避免讹误,这就十分有用。首先会将输入文件中的字符数据从该修饰符所指定的代码页转换成当前的系统代码页,然后从当前系统代码页转换成数据库代码页。请记住,如果输入文件包含了当前系统代码页不识别的字符,就无法将该字符导入或载入数据库。而且,在代码页转换中占用空间变大的数据可能会被截掉。关于通过 DB2 数据移动实用工具进行代码页转换的更多信息,请参阅 DB2 UDB 命令行处理器和实用程序的本地语言支持

create table stafftemp like staff;

export to staffdata.del of del messages export.msg select * from staff;

load from staffdata.del of del modified by codepage=850 messages load.msg insert into stafftemp;

dateformat=" x"

no

yes

yes

指定一个字符串,用于表示导入或载入数据的日期格式。每个未指定的元素将被赋值为 1。关于所有有效日期元素的描述,请参阅 IBM DB2 Universal Database Data Movement Utilities Guide and Reference

考虑导入数据文件 salesdata.asc 的内容为: 23.04.2004LUCCHESSI++++++Ontario-South+++++++++++10 2

create table salestemp like sales;

import from salesdata.asc of asc modified by dateformat="DD.MM.YYYY" method l (1 10, 11 25, 26 40, 41 51) messages import.msg insert into salestemp;

dumpfile= x

no

no

yes

指定一个异常文件的全限定名,所有被拒绝的行都将写入该文件中。

考虑载入输入文件 orgdata.asc 的内容为:++++++l0Head Office++++++++160Corporate+New York+++++ 2

create table orgtemp like org;

load from orgdata.asc of asc modified by dumpfile=/home/melnyk/DUMP.FILE method l (1 8, 9 22, 23 30, 31 40, 41 53) messages load.msg insert into orgtemp;

fastparse

no

no

yes 3

指定在载入输入数据时减少语法检查。该修饰符可以充分地提高性能,在您确信数据是干净的时候推荐使用。

考虑载入输入文件 orgdata.asc 的内容为:++++++10Head Office++++++++1z0Corporate+New York+++++ 2

create table orgtemp like org;

load from orgdata.asc of asc modified by fastparse method l (1 8, 9 22, 23 30, 31 40, 41 53) messages load.msg insert into orgtemp;

implieddecimal

no

yes

yes

指定隐式小数点的位置将由列定义来确定,且不表示该值的结束。

考虑导入数据文件 decdata.asc 的内容为:12345:

create table decimals (dec1 decimal(7,2));

import from decdata.asc of asc modified by implieddecimal method l (1 5) messages import.msg insert into decimals;

timeformat=" x"

no

yes

yes

指定一个字符串,用于表示导入或载入数据的时间格式。每个未指定的元素将被赋值为 0。关于所有有效时间元素的描述,请参阅 IBM DB2 Universal Database Data Movement Utilities Guide and Reference

考虑载入输入文件 timedata.asc 的内容为:10.56 PM:

create table times (timeofday time);

load from timedata.asc of asc modified by timeformat="HH.MM TT" method l (1 8) messages load.msg insert into times;

timestampformat=" x"

See Table 5.

yes

yes

指定一个字符串,用于表示导入或载入数据的时间戳格式。在指定 month 和 minute 元素时,一定要避免二义性,因为两者都使用了字母“M”。month 元素必须邻接其他日期元素,而 minute 元素必须邻接其他时间元素。关于所有有效时间戳元素的描述,请参阅 IBM DB2 Universal Database Data Movement Utilities Guide and Reference

create table in_traytemp like in_tray;

insert into in_tray values ('2004-04-16-17.12.30.000000', 'Melnyk', 'Any subject', 'Any note text');

export to in_traydata.del of del modified by timestampformat="yyyy.mm.dd hh:mm tt" messages export.msg select * from in_tray;

load from in_traydata.del of del modified by timestampformat="yyyy.mm.dd hh:mm tt" messages load.msg insert into in_traytemp;

usegraphiccodepage

no

yes

yes

指定使用图形代码页导入或载入单字节和双字节数据文件中的图形或可变长度的数据。该修饰符支持同时包含字符和图形代码页中数据的输入数据文件。在恢复被删除表时,如果要恢复的表中包含图形数据,该修饰符就极其有用。ROLLFORWARD DATABASE 命令允许您选择将以前删除的表的恢复数据写入 DEL 文件中,该文件可同时包含字符和图形代码页。不要对由 DB2 导出实用工具所生成的数据文件使用该修饰符。这类文件只包含一种代码页。

考虑载入输入文件 data_1208_1200,其中包含值 "adil"(VARCHAR(20))和 "adil"(VARGRAPHIC(20)):

create database db1208 using codeset UTF-8 territory US;

connect to db1208;

create table t1 (c1 varchar(20), c2 vargraphic(20));

load from data_1208_1200 of del modified by codepage=1208 usegraphiccodepage messages load.msg insert into t1;

select * from t1;

字符数据在代码页 1208(UTF-8)中,图形数据在代码页 1200(UTF-16)中。载入输入文件(data_1208_1200)可能是在恢复这个 Unicode 数据库中所删除的一个表时创建的。

1该修饰符不能用于 CURSOR 文件类型。

2输入数据中的每个加号(+)字符表示一个空白字符。这里包含加号字符只是为了清晰地说明,在您尝试该示例之前,应该将其替换为空白字符。

3 该修饰符不能用于 CURSOR 或 PC/IXF 文件类型。

表 4. 可用于非定界 ASCII(ASC)文件类型的文件类型修饰符



修饰符

Export

Import

Load

描述

示例

binarynumerics

no

no

yes

指定载入的输入文件中的数字(非十进制)数据以二进制格式存储(不要与二进制数相混淆,如 00110110)。该修饰符可以提高性能,因为它避免了代价较高的转换;它必须与 reclen 修饰符一同指定。十进制数据的等价修饰符是 packeddecimal

考虑载入输入文件 bigtbl_bin.asc,其中包含二进制格式的值 -32767(SMALLINT)、2147483646(INTEGER)和 9223372036854775799(BIGINT):

load from bigtbl_bin.asc of asc modified by reclen=15 binarynumerics method l (1 2, 3 6, 7 14) messages load.msg insert into bigtbl;

nochecklengths

no

yes

yes

指定即使输入数据超出了目标表中列的大小,也应该尝试导入或载入每一行。如果您知道输入数据将适合所有的情况,就可以使用该修饰符。

考虑导入数据文件 orgdata.asc 的内容为:++++++10Head Office++++++++160Corporate+New York (The Big Apple) 1

create table orgtemp like org;

import from orgdata.asc of asc modified by nochecklengths method l (1 8, 9 22, 23 30, 31 40, 41 64) messages import.msg insert into orgtemp;

nullindchar= x

no

yes

yes

指定 x的值(单个字符)将用于替换作为空指示器值的‘Y’。

考虑导入数据文件 namesdata.asc 的内容为:Rosemary+++++++++++++++n 1

create table names (firstname varchar(12), lastname varchar(12));

import from namesdata.asc of asc modified by nullindchar=N method l (1 12, 13 24) null indicators (12, 24) messages import.msg insert into names;

select * from names;

packeddecimal

no

no

yes

指定载入输入文件中的十进制数据是以压缩十进制格式存放的(压缩十进制编码使用一个字节来表示两个十进制数字)。该修饰符可以提高性能,因为它避免了代价较高的转换;它必须与 reclen 修饰符一同指定。非十进制数字数据的等价修饰符是 binarynumerics

考虑载入输入文件 bigtbl_bp.asc,其中包含压缩十进制格式的值 -45.50(DECIMAL(4,2)):

load from bigtbl_bp.asc of asc modified by reclen=4 packeddecimal method l (1 3) messages load.msg insert into bigtbl;

reclen= x

no

yes

yes

指定 DB2 导入实用工具或 DB2 载入实用工具每行将读取 x个字符,且不将换行字符解释为一行的结束。 x的最大值为 32,767。

考虑导入数据文件 namesdata.asc 的内容为:Rosemary++++Joanna++++++ 1

create table names (name varchar(12));

import from namesdata.asc of asc modified by reclen=12 method l (1 12, 13 24) messages import.msg insert into names;

select * from names;

striptblanks

no

yes

yes

指定当将数据导入或载入可变长度的列时,要截去所有结尾的空白字符。

考虑载入输入文件 orgdata.asc 的内容为:++++++10Head Office++++++++160Corporate+New York+++++ 1

create table orgtemp like org;

load from orgdata.asc of asc modified by striptblanks method l (1 8, 9 22, 23 30, 31 40, 41 53) messages load.msg insert into orgtemp;

select location concat division from orgtemp;

striptnulls

no

yes

yes

指定当将数据导入或载入可变长度的列时,要截去所有结尾的空字符。

考虑载入输入文件 orgdata.asc 的内容为:++++++10Head Office++++++++160Corporate+New York+---- 1,2

create table orgtemp like org;

load from orgdata.asc of asc modified by striptnulls method l (1 8, 9 22, 23 30, 31 40, 41 53) messages load.msg insert into orgtemp;

select location concat division from orgtemp;

zoneddecimal

no

no

yes

指定载入输入文件中的十进制数据是以区位十进制格式存放的(区位十进制编码使用一个字节来表示一个十进制数字)。该修饰符可以提高性能,因为它避免了代价较高的转换;它必须与 reclen 修饰符一同指定。非十进制数字数据的等价修饰符是 binarynumerics

考虑载入输入文件 zoneddata.asc,其中包含区位十进制格式的值 -123.45(DECIMAL(5,2)):

load from zoneddata.asc of asc modified by reclen=6 zoneddecimal method l (1 5) messages load.msg insert into zoned_dec;

1输入数据中的每个加号(+)字符表示一个空白字符。这里包含加号字符只是为了清晰地说明,在您尝试该示例之前,应该将其替换为空白字符。

2输入数据中的每个减号(-)字符表示一个空字符。这里包含减号字符只是为了清晰地说明,在您尝试该示例之前,应该将其替换为空字符。您可以使用 hex 编辑器来生成空字符,其 hex 值为零。

表 5. 可用于定界 ASCII(DEL)文件类型的文件类型修饰符



修饰符

Export

Import

Load

描述

示例

chardel x

yes

yes

yes

指定 x的值(单个字符)将用于代替双引号来括住字符串数据。要将单引号指定为字符串定界符,就对它指定两次,如示例所示。

export to orgdata.del of del modified by chardel'' messages export.msg select * from org;

codepage= x

yes

见表 3

见表 3

指定一个 ASCII 字符串,用于表示要导出数据的目标代码页。如果您需要当在运行于不同代码页的系统之间移动数据时避免讹误,这就十分有用。首先会将字符数据从数据库代码页转换成当前系统代码页,然后从当前系统代码页转换成该修饰符所指定的代码页。关于通过 DB2 数据移动实用工具进行代码页转换的更多信息,请参阅 DB2 UDB 命令行处理器和实用程序的本地语言支持

export to staffdata.del of del modified by codepage=850 messages export.msg select * from staff;

coldel x

yes

yes

yes

指定 x的值(单个字符),将用于代替逗号来分隔列数据。

create table orgtemp like org;

export to orgdata.del of del modified by coldel; messages export.msg select * from org;

import from orgdata.del of del modified by coldel; messages import.msg insert into orgtemp;

datesiso

yes

no

no

指定将日期值按 ISO 格式("YYYY-MM-DD")导出。

export to salesdata.del of del modified by datesiso messages export.msg select * from sales;

decplusblank

yes

yes

yes

指定不要在正的十进制值前面加上加号(+)。

create table stafftemp like staff;

import from staffdata.del of del modified by decplusblank messages import.msg insert into stafftemp;

decpt x

yes

yes

yes

指定 x的值(单个字符),将用于代替句号来作为小数点字符。

create table stafftemp like staff;

export to staffdata.del of del modified by decpt# messages export.msg select * from staff;

load from staffdata.del of del modified by decpt# messages load.msg insert into stafftemp;

delprioritychar

no

yes

yes

指定在执行导入或载入操作时,定界符的处理按照以下先后次序来进行:字符、行、列。这将确保字符串数据 里面出现的回车或换行字符不会被误解为行定界符,但如果实施默认的先后次序(行、字符、列),就会发生该问题。

考虑载入输入文件 contactsdata.del 的内容为:"Tallerico","123 Anyplace Street

Ourtown H0H 0H0":

create table contacts (lastname varchar(16), address varchar(64));

load from contactsdata.del of del modified by delprioritychar messages load.msg insert into contacts;

select * from contacts;

dldel x

yes

yes

yes

指定 x的值(单个字符),将用于代替分号来作为 DATALINK 值的字段分隔符。

create table mydl (name varchar(16), dldata datalink);

insert into mydl values ('Tallerico', DLVALUE('http://dlfs.almaden.ibm.com/x/y/a.b','URL','A comment'));

export to mydldata.del of del modified by dldel* messages export.msg select * from mydl;

keepblanks

no

yes

yes

指定在执行导入或载入操作时,要保留 CHAR、VARCHAR、LONG VARCHAR 或 CLOB 等类型列中开头或结尾的空白字符(不包含在字符定界符之中)。如果您所定义的非空(NOT NULL)列包含一个或多个空白字符,且这些空白字符表示有效数据,该修饰符就极其有用。如果您在导入或载入这些数据时未指定 keepblanks 修饰符,实用工具将试图用一个空(null)值来替换空白字符,但因为该列是不可为空的,所以实用工具会返回一个错误。请注意,在载入 CHAR 列时,总是会在 结尾的空白中填入该列长度,但是, keepblanks 修饰符对于保留 CHAR 列中 开头的空白是有必要的。

create table names (lastname char(16), firstname char(16));

create table newnames like names;

insert into names values (' Tallerico ', ' Teresa ');

export to names.del of del modified by nochardel messages export.msg select * from names;

load from names.del of del modified by keepblanks messages load.msg insert into newnames;

select firstname concat lastname from newnames;

nochardel

yes

yes

yes

指定字符定界符将被解析为列数据。该修饰符用于支持供应商的数据文件,其中不包含字符定界符。要小心使用该修饰符;不正确的使用可能导致数据丢失或讹误。

create table stafftemp like staff;

export to staffdata.del of del modified by nochardel messages export.msg select * from staff;

import from staffdata.del of del modified by nochardel messages import.msg insert into stafftemp;

nodoubledel

yes

yes

yes

指定将取消对于双字符定界符的识别。在打算将一个定界符字符作为实际数据来看待时,通常会将该字符重复一次。引入该修饰符是为了支持向后的兼容性,例如,如果您运行 DB2 导出实用工具来为一个供应商应用程序生成输入数据文件,该程序不支持从 DB2 UDB 版本 5 才开始流行的双定界符逻辑,该修饰符就十分有用。

export to in_traydata.del of del modified by nodoubledel messages export.msg select * from in_tray;

striplzeros

yes

no

no

指定将从导出的十进制列中除去作为开头的零值。

export to staffdata.del of del modified by striplzeros messages export.msg select * from staff;

timestampformat=" x"

yes

See Table 3.

See Table 3.

指定一个字符串,用于表示导入或载入数据的时间戳格式。在指定 month 和 minute 元素时,一定要避免二义性,因为两者都使用了字母“M”。month 元素必须邻接其他日期元素,而 minute 元素必须邻接其他时间元素。关于所有有效时间戳元素的描述,请参阅 IBM DB2 Universal Database Data Movement Utilities Guide and Reference

insert into in_tray values ('2004-04-16-17.12.30.000000', 'Melnyk', 'Any subject', 'Any note text');

export to in_traydata.del of del modified by timestampformat="yyyy.mm.dd hh:mm tt" messages export.msg select * from in_tray;

表 6. 可用于 PC/IXF 文件类型的文件类型修饰符



修饰符

Export

Import

Load

描述

示例

forcein

no

yes

yes

指定导入或载入实用工具不会由于代码页不匹配而拒绝数据,并取消代码页之间的转换。该修饰符必须谨慎使用,但是当处理包含了其他情况下无法导入或载入的数据类型或值时,该修饰符就十分有用。关于该修饰符及其使用的详细信息,请参阅 IBM DB2 Universal Database Data Movement Utilities Guide and Reference

create table resumes like emp_resume;

export to emp_resumedata.ixf of ixf messages export.msg select * from emp_resume;

load from emp_resumedata.ixf of ixf modified by forcein messages load.msg insert into resumes;

indexixf

no

yes

no

指定导入实用工具将删除表上所定义的所有索引,并由 PC/IXF 文件中的索引定义创建一个新的。该修饰符只能在表中内容要被替换时使用。

create table newemp like employee;

export to empdata.ixf of ixf messages export.msg select * from employee;

import from empdata.ixf of ixf modified by indexixf messages import.msg replace_create into newemp;

indexschema= schema

no

yes

no

指定创建索引时将使用的模式名。如果您未指定 schema 的值,就会用连接用户 ID 来代替。如果未指定 indexschema 修饰符,就使用 PC/IXF 文件中的模式。

create table newemp like employee;

export to empdata.ixf of ixf messages export.msg select * from employee;

import from empdata.ixf of ixf modified by indexschema=SHREK messages import.msg insert into newemp;

nochecklengths

no

yes

yes

指定即使输入数据超出了目标表列的大小,也应该尝试导入或载入每一行。如果您知道输入数据将适合所有情况,就可以使用该修饰符。

create table resumes like emp_resume;

export to emp_resumedata.ixf of ixf messages export.msg select * from emp_resume;

load from emp_resumedata.ixf of ixf modified by nochecklengths messages load.msg insert into resumes;


打开db2数据库是在哪个文件 db2加载数据文件_打开db2数据库是在哪个文件_02


打开db2数据库是在哪个文件 db2加载数据文件_数据_03

打开db2数据库是在哪个文件 db2加载数据文件_数据_04


打开db2数据库是在哪个文件 db2加载数据文件_数据_05

回页首



结束语



DB2 数据移动实用工具的文件类型修饰符给您提供了许多不同的选项来定制您的数据移动操作。它们有助于在各种各样的配置中简化数据的导出、导入和载入,并且当在数据库表中移入或移出大量数据时,可用于使实用工具更高效地运行。您可以很容易地改造本文中的示例以便用您自己的数据做试验,并且找出在您的环境中利用这些修饰符的新方法。





参考资料


  • 您可以参阅本文在 developerWorks 全球站点上的 英文原文.
  • DB2 Technical Support是一个查找版本 8 信息中心和 PDF 产品手册等参考资料的理想场所。
  • IBM DB2 Universal Database Data Movement Utilities Guide and Reference提供了关于 DB2 数据移动实用工具的详细信息。



关于作者



打开db2数据库是在哪个文件 db2加载数据文件_数据_04


打开db2数据库是在哪个文件 db2加载数据文件_数据_07

DB2 Version 8: The Official Guide(Prentice Hall Professional Technical Reference,2003)、 DB2: The Complete Reference(Osborne/McGraw-Hill,2001)、 DB2 Fundamentals Certification for Dummies(Hungry Minds,2001)和 DB2 for Dummies(IDG Books,2000)。




转载于:https://blog.51cto.com/77857/200456