DB2中export命令詳解<<轉載>>

myamor發表於2012-03-27

<>----原作者太多了,反正不是我寫的

1、匯出使用者必須有SYSADM或DBADM授權,或者在表格上擁有CONTROL或SELECT許可權;
2、不支援帶結構列的表格資料匯出;
3、可以匯出帶identity列的表格為ixf格式,匯入時用REPLACE_CREATE、CREATE重建identity列,如果該列定義是GENERATED ALWAYS,匯入時則必須指定identityignore選項。
4、指定匯出格式為ixf,ixf檔案中含有表格和索引定義,用import可以重建表格和索引,但是下面情況ixf檔案會丟失相關資訊:
* index column names contain hexadecimal values of 0×2B or 0×2D
* table contains XML columns
* table contains LOB(超過1G的定義) columns
* table is multidimensional clustered
* table contains a table partitioning key
* index name that is longer than 128 bytes due to codepage conversion
* table is a protected table
* contains action strings other than SELECT * FROM
* method N is specified
5、如果匯出檔案太大,可以使用where條件限制匯出的資料量,分批匯出;
6、匯出檔案格式:
* DEL (delimited ASCII format)
* WSF (work sheet format)
* IXF (integrated exchange format, PC version)
7、執行匯出命令前,確認完成了commit或rollback;
8、匯出格式為DEL時,如果字元列長度超過254時會有警告提示;
9、匯出包是與DATETIME ISO格式繫結的,所以在sql語句中需要使用iso格式:
查詢資料庫(返回3行資料)
db2 select col2 from tab1 where char(col2)=’05/10/2005’;
3 record(s) selected.
匯出時使用locale格式不能選擇到記錄
db2 export to test.del of del select col2 from test where char(col2)=’05/10/2005’;
Number of rows exported: 0
由locale格式改為iso格式
db2 export to test.del of del select col2 from test where char(col2)=’2005-05-10’;
Number of rows exported: 3
10、匯出執行的三種方式
* CLP命令:export
* ADMIN_CMD儲存過程的export過程
* db2export的API介面,使用c語言實現
11、del檔案格式指定引數舉例:db2 “export to myfile.del of del modified by chardel’’ coldel; decpt, select * from staff”
chardelx: 指定字串的分隔符,預設是雙引號,可以指定為單引號modified by chardel'’
coldelx:指定列分隔符,預設是逗號,可以改為分號modified by coldel;
decplusblank:指定對正數是否用+符號,預設帶+,可以指定不加正數符號
striplzeros:指定移走資料前導的0,如:+00001.8–>+1.8
測試如下
db2 “export to tb1-1.del of del select * from tb1″
+00000002.10,”abc”
db2 “export to tb1-2.del of del modified by chardel'’ coldel; decplusblank striplzeros select * from tb1″
2.10;’abc’
timestampformat=″x″時間戳格式設定,如:”YYYY/MM/DD HH:MM:SS.UUUUUU”、”yyyy.mm.dd hh:mm tt”
YYYY - Year (four digits ranging from 0000 - 9999)
M - Month (one or two digits ranging from 1 - 12)
MM - Month (two digits ranging from 01 - 12)
D - Day (one or two digits ranging from 1 - 31)
DD - Day (two digits ranging from 1 - 31)
H - Hour (one or two digits ranging from 0 - 12 for a 12 hour system, and 0 - 24 for a 24 hour system)
HH - Hour (two digits ranging from 0 - 12 for a 12 hour system, and 0 - 24 for a 24 hour system)
M - Minute (one or two digits ranging from 0 - 59)
MM - Minute (two digits ranging from 0 - 59)
S - Second (one or two digits ranging from 0 - 59)
SS - Second (two digits ranging from 0 - 59)
UUUUUU - Microsecond (6 digits ranging from 000000 - 999999)
UUUUU - Microsecond (5 digits ranging from 00000 - 99999)
UUUU - Microsecond (4 digits ranging from 0000 - 9999)
UUU - Microsecond (3 digits ranging from 000 - 999)
UU - Microsecond (2 digits ranging from 00 - 99)
U - Microsecond (1 digit ranging from 0 - 9)
TT - Meridian indicator (AM or PM)
如果指定了TT,HH就會在0-12之間顯示

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/177006/viewspace-719606/,如需轉載,請註明出處,否則將追究法律責任。

相關文章